When to use PUT or POST in RESTful Web Service

One of the most common confusion among web developers is the choice of PUT or POST HTTP method for creating or updating a resource while developing RESTful Web Services. Since both can be used to submit data, you can use either POST or PUT to create or update a resource. Many web developers want to use PUT for creating a resource on the server because it's idempotent. No matter, how many times you call the PUT, the state of the resource will not jeopardize. Since the possibility of re-submission is real on a slow network, using PUT to create resource makes it easy, as you don't need to worry about user clicking the submit button multiple times. But, the key point to remember is that when you use PUT to create a resource, you need to provide the id e.g.

How to print all leaf nodes of binary tree in Java?

This is another interesting coding problem which is based on binary tree and like many other binary tree algorithms, you can use recursion to print all leaf nodes of a binary tree in Java. Since the tree is a recursive data structure, you can apply the same algorithm to the left and right subtree. A leaf node is the one whose left and right child nodes are null. So you can print all leaf nodes by traversing the tree, checking if the left and right nodes are null and then printing that leaf node. The logic is very much similar to post order traversal but instead of just printing node, we first check if both left and right children are null or not. It is also one of the frequently asked coding questions. Since the binary tree is an essential part of Data structures and algorithms, you can expect a couple of questions on binary trees and BST e.g. whether a given tree is binary search tree or not? This one is rather simple but it can be tricky if interviewer also asks you to solve this problem without recursion, as discussed here.

Map Reduce Example in Java 8

The map-reduce concept is one of the powerful concept in computer programming which utilizes the power of distributed and parallel processing to solve a big and heavy problems in quick time. From Java 8 onwards, Java also got this powerful feature from functional programming world. Many of the services provided by internet e.g. Google Search are based on the concept of the map and reduce. In  map reduce a job is usually split into the input data-set into independent chunks which are processed by the map tasks in a completely parallel manner. The framework sorts the outputs of the maps, which are then inputted to the reduce tasks. For example, suppose you want to calculate the average age of all the people in a town, instead of counting sequentially you can first calculate their age using the map and then calculate the average using reduce.