Monday, August 29, 2016

Java Design Pattern Interview questions

If two different class loaders load a singleton class, would they load it twice ?
Two objects loaded by different class loaders are never equal even if they carry the same values.
So, each class loader will have its own singleton.

What is Decorator design pattern?
The decorator design pattern attaches responsibilities to objects at runtime.
BufferedInputStream in java.io is an example of Decorator. It wraps around a InputStream and provide additional buffering functionality.

What is Strategy design pattern?
Strategy design pattern lets you swap new algorithms and processes into your program without
affecting the objects that use them.
AWT containers delegate the layout to layout managers. Layout managers use strategy pattern to for appropriate layout.

What is Iterator Design pattern?
 Iterator pattern is used to iterate over a collection sequentially and provide a way the access the individual elements.

What is Factory pattern?
 Factory pattern abstracts the object creation process from the code that uses the objects.

What is Front Controller design pattern?
Front controller suggest using a single servlet for centralizing request handling and delegating functions like validation and business process handling to helpers.

What is Composite view pattern?
A composite view is made of several sub-views.
A JSP page can use a header jsp, footer jsp etc.

What is View Helper pattern?
In this pattern, the view delegates processing responsibilities to helper classes.
Implemented using Javabeans.

Difference between Service to Worker pattern and Dispatcher View pattern.
Both pattern use Front controller combined with Helpers with Dispatcher component.
In Service to worker, front controller delegates content retrieval to View Helpers. Controller also takes care of tasks like authentication, authorization etc.
In Dispatcher View, Controller does not delegate content retrieval to helpers. Most of the work is done by views.


No comments:

Post a Comment