Saturday, November 19, 2016

Java Design Pattern Interview Questions

In this Page, we will learn frequently asked Design Patterns Interview Questions, which are most managers expect from their developers to have depth knowledge on important patterns. These Interview questions are asked in various java interview. 

Fallowing are the Java Design Pattern Interview Questions:

1) What is Design Pattern?

Ans:

Design Pattern is a general resolution to a commonly occurring problem with in a specific context when designing an application or system . These are tried and tested way to solve particular design issues by various programmers. 


2) What are the elements in Design Pattern?

Ans: There are 3 main elements in Design Pattern . They are

a) Context
b)Problem
c) Solution

a) Context:

It is a recurring situation in which a problem to be solved is found. 

b) Problem:

The problem describes when to apply the pattern. It might describe a specific design problem such as how represent  algorithms as objects. 

c) Solution:

In this pattern provides abstract description of a design problem and how the arrangements of classes and objects to solve it. It works as a template which can be fulfilled with the code.

Note:  The design pattern contains not only above three elements, The relationship between three and formal language that describe the whole business.

3) Can you name few Design Pattern used in Standard JDK library?

Ans:

In JDK library few of the design patterns were used, they are Decorator design pattern which is used in various Java I/O classes,Singleton Pattern which is used in Runtime,Calendar and various other classes,Factory pattern which is used along with various immutable classes like Boolean  and Observer pattern which is used in Swing and many event listener frameworks.



4) What is MVC Design Pattern?

Ans:

MVC means Model-View-Controller, It is a clear functional separation of roles. That means it separate the application logic from the user interface and control between the user interface and the application logic. 

Model: The model represents data and the rules that govern access to and updates of this data. In java program language usually model is Java Beans. The main responsibility of model is to interact with persistence storage to store,retrieve and manipulate data.

View: The view renders the contents of a model. That means it is responsible for displaying results back to the user.This is usually implemented by using JSP.

Controller:  It translates the user's request and select appropriate view to return. The controller job is done by Servelts

5) What is Singleton Design Pattern ?

Ans:  A Singleton is a class which only allows a single instance of itself to be created,and usually gives simple access to that instance. It focus on sharing of expensive object in whole system. Only one instance of of a particular class is maintained in whole application which is shared by all modules.

For more details: Singleton Design Pattern with examples

6) What is factory Design Pattern? where do you use it?

Ans:  The factory Pattern gives us a way to encapsulate the incantations of concrete types. That means it increased level of encapsulation while creating objects. If you use Factory to create object you can later replace original implementation of Products or classes with more advanced and high performance implementation without any change on client layer. 

7) What Front Controller Pattern? Explain?

Ans:  The Front Controller is a entry point to a website. It provides a centralized entry point that controls and manages the web request handling. It is a presentation controller that allows the resources to change without breaking all the bookmarks to a given resource. For Example, Microsoft often changes the contents in it library. The main purpose of this pattern is to isolates the actual resources from direct access by the user. This controller must delegate the request to the proper resource and view.

8)  What is Observer Design Pattern?

Ans:  This pattern is based on communicating changes in state of object to observers so that they can take there action. For example, A whether system where change in weather must be reflected in views to show to public. Here weather object is Subject while different views are Observers. The other way to understand Observer pattern is publisher-subscriber relationship works. Whenever a new issue is published,it gets delivered to you ,but the publisher continues to work as before, since there are other people also subscribed to that particular Magazine.

9) Give example of Decorator Design Pattern in Java?

Ans: The Decorator Design Pattern is to attach the additional responsibilities to an object dynamically. That means enhances capability of individual object. Java IO uses decorator pattern extensively. For example, Buffered classes like BufferedReader and BufferedWriter which enhances Reader and Writer objects to perform Buffer level reading and writing for improved performance. The main purpose of this pattern is adds the responsibility to the components.

10) What is DAO Pattern?

Ans:  DAO means Data Access Object, it provides a connection between the business logic and the resource usually a database tier. It is a general interface to the resource layer. JDBC or Hibernate most commonly used examples for this. It is an object that encapsulates a set of behaviors for accessing a databases,files and other resources. This way you have only one API to deal with rather than a different one for every type of resource.This pattern proved a uniform API to any persistent data storage.



No comments:

Post a Comment

High Paying Jobs after Learning Python

Everyone knows Python is one of the most demand Programming Language. It is a computer programming language to build web applications and sc...