OOPS Concept Tutorial in Java - Object Oriented Programming

I have written several OOP (Object Oriented Programming) concepts tutorials in past and I was thinking to bring them together so that anyone who wants to learn OOP basics can benefit from them easily. In this article, I will share you my collection of OOP tutorials and OOP concepts interview questions, which will not only help you to understand four pillars of Object Oriented programming e.g. Abstraction, Encapsulation, Inheritance, and Polymorphism but also powerful design techniques of Aggregation, Association and Composition, along with SOLID design principles, which are key to write flexible, extensible and object-oriented software. Java is also a great language to start with object oriented programming, though it's not a pure object oriented language but it is the best one we have got so far. You cannot write code outside Class, which standardize the code organization.

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.