Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Java Design Patterns Interview Questions and Answers

Ques 1. What is design patterns?

Design patterns are tried and tested way to solve particular design issues by various programmers in the world. Design patterns are extension of code reuse.

Is it helpful? Add Comment View Comments

Ques 2. Can you name few design patterns used in standard JDK library?

Decorator design pattern which is used in various Java IO classes, Singleton pattern which is used in Runtime , Calendar and various other classes, Factory pattern which is used along with various Immutable classes likes Boolean e.g. Boolean.valueOf and Observer pattern which is used in Swing and many event listener frameworks.

Is it helpful? Add Comment View Comments

Ques 3. What is Singleton design pattern in Java ? write code for thread-safe singleton in Java.

Singleton pattern focus on sharing of expensive object in whole system. Only one instance of a particular class is maintained in whole application which is shared by all modules. Java.lang.Runtime is a classical example of Singleton design pattern. From Java 5 onwards you can use enum to thread-safe singleton.

Is it helpful? Add Comment View Comments

Ques 4. What is main benefit of using factory pattern? Where do you use it?

Factory pattern’s main benefit is 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.

Is it helpful? Add Comment View Comments

Ques 5. What is observer design pattern in Java?

Observer design pattern is based on communicating changes in state of object to observers so that they can take there action. Simple example is a weather system where change in weather must be reflected in Views to show to public. Here weather object is Subject while different views are Observers.

Is it helpful? Add Comment View Comments

Most helpful rated by users:

©2024 WithoutBook