Through this article, I will be discussing the concept of Encapsulation and how we can achieve it in java programming. After reading this article you would be in a position to understand and implement encapsulation into your next java application.
It is one of the important concepts of OOP like Inheritance, Abstraction, and Polymorphism.
Encapsulation is a mechanism of wrapping the data (instance variables) and code acting on the data (instance methods) together as a single unit(i.e. class).
In encapsulation, the variables of a class will be hidden from other classes(i.e. the other classes of the package and outside the…
You might have heard about nested and inner classes from your peer/senior developers or you may have read about it somewhere on the web. This article will cover everything you need to know about nested and inner classes for your next interview.
The Java language allows you to define a class within another class. For example:
class OuterClass {
...
class NestedClass {
...
}
}
Now note that Nested classes are divided into two categories:
Nested classes that are declared using static
keywords are called static nested classes. …
I have seen many developers a bit confused when it comes to multi-threading. This is primarily because a lot of things happen in the background and many concepts are related to it. You should know Race Condition, Critical section, and Context Switching between threads. I have already covered these concepts and their examples in detail.
Process and Thread Context Switching, Do You Know the Difference?
Synchronization in Java: All You Need to Know
In this article, I’ll be covering two important keywords synchronized and volatile, and their proper usage. …
In Java, every class is a child of the Object class. The Object class contains the toString() method and its definition. We can use the toString() method to get a string representation of an object.
Whenever we print the Object of any class, then the toString() method is invoked internally by the compiler. If we have not defined the toString() method in our class, then the Object class’ toString() method is invoked, otherwise our overridden toString() method will be called and the object’s string representation will be returned by the toString() method.
public String toString()
{
return getClass().getName()+"@"+Integer.toHexString(hashCode());
}
Let’s…
This article is about designing, visualizing, and analyzing the quick sort algorithm. After reading this article you will be able to answer most of the questions related to the quick sort algorithm.
Quicksort is a divide and conquer algorithm. It picks an element as a pivot and partitions the array around the pivot element. The pivot element can be selected in multiple ways:
The idea behind quick sort is to pick an element as a pivot from the given array…
While learning java programming you might have come across the concept of loose and tight coupling. When I was searching on the web for the java interview questions I found this very commonly asked. Many of them have tried to explain in their own way using different examples. But the degree of differences between answers written over the web shows why it would be a difficult concept to grasp but I’ll be discussing it and will try to explain it in the easiest language.
Tight coupling means when a group of classes are highly dependent on one another. This scenario…
Priority Queue data structure and its operations — Insert, Delete, Peek, and Extract-Max.
Hey Friends, this is another data structure article where I’m going to cover priority queue data structure. I have already covered all sorting and searching algorithms. You can find them here. I would request you to read and comment on those articles so that I can improve them over the period.
A priority queue is a type of queue in which each element is associated with a priority and is dequeued according to its priority. …
Know how the compiler converts primitive to the wrapper and vice versa.
While learning Java you might have seen that a lot of things Java Compiler does internally. It becomes easier for the programmer to write clean code but at the same time, the developer should know the internal working of the functionality which he is writing in the application.
In this article, we’ll try to understand the basic features java provides that are AutoBoxing and Unboxing.
Autoboxing is the automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes. For example, converting…
Hi friends, I have already covered all sorting and searching algorithms. You can find them here. I would request you to read and comment on those articles so that I can improve them over the period. Now, this is another data structure article where I’m going to cover circular queue data structure.
In normal queue Implementation, after few enQueue and deQueue operations, there are empty spaces(positions) left out in the queue that are not being used till both the front and rear pointers are reset to -1.
Hi friends, I have already covered all sorting and searching algorithms. You can find them here. I would request you to read and comment on those articles so that I can improve them over the period. Now, this is another data structure article where I’m going to cover queue data structure.
A Queue is a Linear Data Structure that follows a particular order in which the operations are performed.
The order is First In First Out (FIFO). An example of a queue is the ticket counter where a person who came first receives the ticket first and the last standing…