Question 1: How will you design your Singleton Patten class to be thread-safe?
ANSWER: Adding synchronized keyword tothe getSingleton() method is inefficient solution. Initialize the static private Singleton object within Synchronized block. In this way you can achieve it.
Question 2:What Design Pattern can be used for classical Producer Consumer problem?
ANSWER: Use observer pattern (publisher subscriber model)
Question 3:M.S Word can store million lines of text. Each character in the text will have set of properties like font-color, font-size, font-style and etc. So, M.S Word application has to maintain a property structure for each and every character and that may lead to heavy storage. What design pattern will you apply to overcome this problem?
ANSWER: You have to create property group for each possible styles (font-size, font-color, font-face & etc). So, common characters will be part of a property group, there by reducing the storage of each character. This is called FlyWeight Pattern.
Question 4:Your application uses 1000 classes and they have interaction among each other. This will lead to complex communication across objects, so what design pattern can solve this problem?
ANSWER: Use Mediator pattern to separate the direct communication across objects.
Question 5:An application reads input from various clients in multiple stages and creates a binary tree structure out of all received inputs. Which design pattern can be used to design such application?
ANSWER: Building an object in multiple set - you call it Builder pattern! The realworld example is XSDBuilder class in Java.
Question 6:You have to design a budget management application for global users. But, have to provide an option to configure their native tax rules. Which design pattern, do you think, can solve this?
ANSWER: Use Template Pattern. It provides templates of methods and allowing you to override certain portion of logic.
Question 7:You have a core application class. But, you have to be able assign extra functionalities to the core class on the fly (at runtime). Which patterns deserves this purpose?
ANSWER: Decorator Pattern. This is similar to the pattern designed for java.io.* classes(BufferedReader, DataInputStream and etc.)
Question 8: How is the MVC design pattern used in Struts framework ?
Answer: In the MVC design pattern, a central Controller mediates application flow. The Controller delegates requests to an appropriate handler. The handlers are tied to a Model, and each handler acts as an adapter between the request and the Model. The Model represents, or encapsulates, an application’s business logic or state. Control is usually then forwarded back through the Controller to the appropriate View. The forwarding can be determined by consulting a set of mappings, usually loaded from a database or configuration file. This provides a loose coupling between the View and Model, which can make an application significantly easier to create and maintain. Controller: Servlet controller which supplied by Struts itself; View: what you can see on the screen, a JSP page and presentation components; Model: System state and a business logic JavaBeans.
Question 9: What design patterns are used in Struts?
Answer: Struts is based on model 2 MVC (Model-View-Controller) architecture. Struts controller uses the command design pattern and the action classes use the adapter design pattern. The process() method of the RequestProcessor uses the template method design pattern. Struts also implement the following J2EE design patterns.
Service to Worker
Dispatcher View
Composite View (Struts Tiles)
Front Controller
View Helper
Synchronizer Token
Question 10: Question: How would you go about analyzing performance of an application?
Answer: When performance testing a Web application, several requirements must be
determined either through interpretation of data from an existing application that
performs similar work. Those requirements are:
User base
What is the expected number of users that will access this application? This is
generally expressed in hits per month, day, hour, or minute depending on
volumes.
Total concurrent users
During a peak interval, what is the maximum possible number of users
accessing the application at the same time.
Peak request rate
How many pages will need to be served per second?