Java Design Patterns Interview Preparation Guide
Download PDF

Java Patterns Interview Questions and Answers will tech us now that in software engineering, a design pattern is a general reusable solution to a commonly occurring problem in software design. A design pattern is not a finished design that can be transformed directly into code. So start learning Java Design Patterns or get preparation for the job of Java Design Patterns by the help of this Java Design Patterns Interview Questions with Answers guide

29 Java Patterns Questions and Answers:

1 :: What is a software design pattern?

A reusable software design solution in general for the problems that are recurrently occuring. Design pattern is not a solution but a description for how to solve a problem in different situations. OOP design patterns establishes the relationships between classes or objects. Design patterns are specifically dealt with problem solving at the software design level.

2 :: What are the differences between analysis patterns and design patterns?

Analysis pattern are targeted for domain architecture, where as design pattern are targeted for implementation mechanism for some of the aspects of the domain. Analysis patterns are functional oriented and of high level.

3 :: What is an analysis pattern?

It is a software pattern which is not related to a language. It is related to a business domain like health care, telecom. The visiting activity of a patient in the health care domain would be subject to a number of patterns.

4 :: How do you write a Thread Safe Singleton?

The following are the steps to write a thread-safe singleton:

► Declare a Boolean variable, ‘instantiated’, to know the status of instantiation of a class, an object of Object class and a variable of the same class with initial value as null.
► Write a private constructor of this class
► Override getInstance() method. Check the Boolean state of the instance variable ‘instantiated’. If it is false, write a ‘synchronized’ block and test for the current class instance variable. If it is null create an object of the current class and assign it to the instance variable.

The following code illustrates this :

public class SampleSingleton {
private static boolean initialized = false;
private static Object obj = new Object();
private static SampleSingleton instance = null;
private SampleSingleton() {
// construct the singleton instance
public static SampleSingleton getInstance() {
if (!initialized) {
synchronized(obj) {
if (instance == null) {
instance = new SampleSingleton();
initialized = true;
return instance;

5 :: What is Singleton pattern?

Singleton pattern is one of the design patterns that is utilized for restricting instantiation of a class to one or few specific objects. This facility is particularly useful when the system requires to coordinate the actions with exactly one object.

6 :: What are Process Patterns?

Methods, best practices, techniques for developing an Object-Oriented software comprises a process pattern.

7 :: What is the Reactor pattern?

The Reactor pattern is an architectural pattern that allows demultiplexing of event-driven applications and dispatch service requests which are delivered by one or more application clients to an application.

The reactor pattern is used in a manner that is synchronous. So that the delegated callback event takes a while for completing the running problems with scalability.

8 :: What is session facade?

Session Façade is one of the design pattern. It is utilized in developing enterprise applications frequently. Session Façade is implemented as a higher level component like Session in EJB, and has all iterations between low level components like Entity in EJB. After that, it provides an interface that functions an application or part of it. Then it decouples the lower level components by simplifying the design.

9 :: What are Collaboration Patterns?

Repeatable techniques which are utilized by people of different teams for helping them work together. The really have nothing to do with object-oriented development. The fact is that these patterns can support with requirement gathering .

10 :: How do I document a design pattern?

The following are the major points for describing a pattern.

► Short and meaningful name for the pattern is to be selected.
► Problem description and goals and constraints that may occur in that context is to be identified.
► The participating classes and objects in the design pattern and their structure, responsibilities and their collaborations are to be decided. An abstract description is applied in many different situations are provided by the solution.
► Identify the uses in the real systems and its efficiency.