Java Patterns

  Home  Java Programing  Java Patterns


“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

2⟩ 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.

 141 views

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.

 154 views

4⟩ 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.

 150 views

5⟩ 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 .

 160 views

6⟩ 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.

 158 views

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.

 154 views

9⟩ 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;

}

}

 160 views

10⟩ 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.

 166 views

12⟩ Explain about Template method?

Template method is the most common way of representing. Implementation of a method differs for files, sockets, pipes, strings, text entry widgets, etc. When template method is used logic of the entire class is modified. Missing logic can be called by abstract and concrete methods.

 153 views

13⟩ Explain about locks?

Lock is known to be the safest and the basic message control mechanism used in object oriented mechanism. This is used to block the usage of methods while another method is in progress. The only safest way to use lock mechanism is to fully synchronized objects.

 174 views

14⟩ Explain about semaphores?

They are mostly used as concurrency control constructs. They adhere and support Sync interface and conform to acquire release protocol. It adheres to a set of permits initialized in a constructor. A semaphore can also be described on the basis of a metaphor.

 159 views

15⟩ Explain about fully synchronized objects?

In a fully synchronized object all methods are synchronized. Encapsulation violations are generally neglected. Methods are finite which release locks. Even in the presence of exceptions state of the object is at the beginning and end of each method.

 149 views

16⟩ Explain about open systems?

Open systems are used widely by developers than the closed systems because these are attainable and achievable. It can be accessed across several dimensions. Full static analysis is not possible because of their nature and structural evolution which varies according to time. Opensystems may load classes dynamically, can employ call backs, resource sharing, etc.

 159 views

17⟩ Explain about closed subsystems?

In a closed system a developer will have a perfect knowledge about all the possible behaviors and static design time. By employing encapsulation techniques one can close parts of the system. This is possible in product level components and the lower rung of individual classes.

 158 views

18⟩ Explain about particle canvas?

Particle canvas is a sub class of java.awt. Canvas this class provides a drawing area for all the particles. Whenever a paint method is called it invokes draw for all the existing particles. It cannot create object or particles by itself. Existingparticle objects are stored in the array of instance variable particles.

 150 views

19⟩ Explain about state dependence?

State dependence tells you about the action performed on the object whether succeeded or failed, action which can be performed, monitoring methods, postponing, triggering, preventing, etc. This is also used to monitor methods.

 169 views

20⟩ State the purpose of why a Java singleton should be used?

Java singleton is used when a constructor and finalize methods are used only once during the lifetime of the application. If a class is referenced from within then it is garbage collected by the Java which can be retrieved if called again but the problem comes when the constructor or finalize methods are used only once.

 154 views