Category Archives: Interview Questions

Factory design pattern in java

In this post, We will talk and learn about the Factory design pattern in java. Factory pattern comes under a creational design pattern. It is one of the most used design patterns in Java. Using this design pattern we can create an object without exposing the object creation logic to the client and refer to the… Read More »

Prototype Pattern in Java

In this post, We will talk and learn about Prototype Pattern in Java. Prototype comes under a creational design pattern that makes use of cloning objects if object creation complex and time-consuming. Below is the complete source code: Student.java Model class

StudentDAO.java creates Cloned Object that makes use of  Prototype Pattern:

Test.java Client Program:

Output… Read More »

Singleton Design Pattern in java

In the previous post, Java Design Pattern which talks list of design patterns available in java In this post, we will learn what is Singleton design pattern and it’s different implementations. Singleton design patterns help us to create one and only one object of a class within the JVM.  Singleton Eager initialization Singleton Lazy Initialization Thread Safe Singleton… Read More »

How to Convert List to Map using Java 8

In this post, we will learn How to convert List to Map using Java 8 Stream API, where a key is any attribute from the object and value is the object itself or any attribute from Object. Let’s clarify it using the below example. Employee.java

StreamApiExample.java

Output of this program: ——-Getting Map from… Read More »

Semaphore Example in Java ?

In this post, We will talk and learn about Semaphore in Java using an Example. A counting Semaphore is from java.util.concurrent package which maintains a set of permits. Each call of acquire() blocks if necessary until a permit is available, and then takes it. Each call of release() adds a permit. The Semaphore usually keeps a count of the number available… Read More »

CyclicBarrier Example in Java ?

In this post, We will talk and learn about CyclicBarrier in Java using an Example. A CyclicBarrier is a synchronization helping class from java.util.concurrent package that allows a set of threads to all wait for each other to reach at common barrier point. CyclicBarrier is useful when a program involves a fixed sized party of threads… Read More »

CountDownLatch Example in Java

In this post, We will talk and learn about CountDownLatch in Java using an Example. CountDownLatch  is a synchronization helping class that allows one or more threads to wait until a set of operations being performed in other threads completes. A CountDownLatch has to initialize with a given count. The await method blocks until and unless the current count reaches to… Read More »

Java Spliterator Example

In this post, We will talk and learn about Java Spliterator Using an example Java Spliterator interface is an example of an internal iterator that breaks down the stream into the smaller parts and these smaller parts can be processed in parallel. Features  Of Spliterator : The following are the list of features provided by Spliterator in Java. Spliterator… Read More »