17
November

Patterns are so important, if you are giving a software developer interview for any OO (Object Oriented) language (Java, C#, C++) and technology (.Net, J2EE). Patterns give solutions for frequently recurring design problems, and they are language neutral.

The book, Design Patterns: Elements of Reusable Object-Oriented Software, (is the defacto standard for Patterns and it covers 23 design Patterns in detail. The book is must read, if you want to master in Patterns or answer any Pattern related interview question.

I have compiled the following Java Design Pattern Interview questions. I must say this, because the questions are more relevant to Java, however, they apply for other languages also. The questions test your design patterns application knowledge.

  1. How will you design your Singleton Patten class to be thread-safe? (a standard interview question!)
  2. What Design Pattern can be used for classical Producer Consumer problem? (a simple 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?
  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?
  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?
  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?
  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?

All these questions are my own; there may be some errors too. Please bring it to notice, if you find anything wrong. I appreciate you readers to post the answers; otherwise I’ll post the answers if you need :)

(PS: If you are interested, please subscribe to the comment notification option, provided just below the comment text box. You will get a notification when somebody posts the answer)

Related posts:

  1. Java Interview Questions, Tricks and Tips. Oh no, this is not an yet another article posting...
  2. Google Interview Questions There is a big hype for working in Google. At...
  3. JSP Servlet Interview questions Many people have requested to post JSP Servlets scenario based...
  4. SCJP 1.5 mock exam questions, books - which are best? You could find hundreds of thousands of result in google...
  5. Java Threads Interview Questions Many people feel that Threads and Collection APIs are somewhat...

Related posts brought to you by Yet Another Related Posts Plugin.

Category : Java J2EE Interview Questions / Technical

Comments

sivakumar November 17, 2008

Nice questions. the book you mentioned is old, right? where can i get examples for design patterns in Java?

Deepak November 17, 2008

Hi,
whenever you post interview questions, please post the answers too.
Thanks
Deepak.

ravikumar November 18, 2008

hi mani i wud lik to knw the ans for those qs..cud u pl send dem to ..itsrkk@gmail.com

Manivannan Palanichamy November 19, 2008

@ravikumar: I am sorry, your email is not complelty visible (or wonder, if that is your actual email). Will suggest you to tick the notification option while posting your comment. In this way, you will be notified when somebody posts answers in the comment.

selvakumar November 21, 2008

Nice questions.

rkk November 23, 2008

hey mani no body seems to know the ans’s ..so y dont u post dem…i very much desperate to knw dem..it will be a grt help ,for my preparation to my next job

Manivannan Palanichamy November 23, 2008

sure rkk. here go the answers.

1. 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.

2.ANSWER: Use observer pattern (publisher subscriber model)

3. 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.

4. ANSWER: Use Mediator pattern to separate the direct communication across objects.

5. ANSWER: Building an object in multiple set - you call it Builder pattern! The realworld example is XSDBuilder class in Java.

6. ANSWER: Use Template Pattern. It provides templates of methods and allowing you to override certain portion of logic.

7. ANSWER: Decorator Pattern. This is similar to the pattern designed for java.io.* classes(BufferedReader, DataInputStream and etc.)

Cool. Ask me for any further clarification :)

rkk November 25, 2008

hi mani,if u have more Q’s on design patterns keep posted…

thankz anyway for the ans’s
we expect more frm u.

Manivannan Palanichamy November 25, 2008

@rkk: thanks
Sure, will post more on that.

rkk January 15, 2009

hi mani,i dunno vethr this is an appropriate question here,,,,,,but i thot u cud be of some help or any one for dat matter
could you plz tell what exactly a senior j2ee developer’s respos would be in a j2ee spring project ….the thing is im trying to make it as a senior developer i ve strong knowledge on spring,hibernate,ooad,uml,but not much of real time exp…
im confused wat i wud be asked in the intrvw, coz its for a senior position…n i dont want to make a fool out of myself…i want to ans at least 50% of the q’s accurately for vich i ve the potential….

thanking u in advance…
if any one has a j2ee spring project and the q’s related to dat ,dat wud be of grt help …

Manivannan Palanichamy January 19, 2009

Hi rkk,

A senior developer would be mostly be an individual contributor or taking a lead role. Hence, need to be strong technically very well.

I’ve never used Spring framework, hence dont have much knowledge on this. But, will post some ideas, when time permits :)

rkk January 20, 2009

hi mani,wat i wud like to know is ….wat docs would be given to the senior developer in a project(say a web application)wat wud be his deliverables
say for ex the respos are
:Involved in gathering business requirements from the client.—-how does he do that?????
.Involved in preparing detail design document for the <> module.—-can i have a sample or any links wud do
.Created class diagrams and sequence diagrams using Eclipse—this is done in the detailed desgn doc if im not wrong
.Created action classes, form classes for module <> using struts framework.—this done based on the detailed design doc correct me if im wrong
.Created jsps for <> module and tested those pages by deploying them in wsad.
.Used design patterns like MVC, Singleton, Business delegate
.Used ANT as build tool.
.Used Hibernate for mapping objects to the relational database.

clarify me on this…

can any one share their experiences as a senior j2ee developer in a project….ur day to day activities and others such…

rkk January 21, 2009

hi mani,cud u plz give the list of design patterns and tell when and in wich situation are they used ….i had gone thru the design patterns book…but i need it from u…coz ur explanation is quite simple ….its no flattery

Manivannan Palanichamy January 21, 2009

hi rkk,
sure. but, i need enough time to write big posts :) will be posting it periodically.

niraj November 17, 2009

thanks

Michale December 12, 2009

Thank for sharing.

raj January 15, 2010

hi mani this rellay nice answer of the question.
could you please provide the more scenario means
question and answer.

Thanks
Raj

Karthick Prabhu January 28, 2010

Hi Mani,

I came across your blog today. Nice blog :)

i have a question ..which design pattend does log 4j use?

Arokia April 14, 2010

hi Mani,

Can you give real world examples for OOAD.

How to think OOAD and produce classed by applying design patterns.

How to design classes for Java Enterprise application?

basu May 19, 2010

hi man…thanks a lot..google is my dream…
since im in 6th sem of B.E can you advice me wat all i need to do to get through interview.. thanks

suresh kumar July 23, 2010

hi mani,

plz…can u list out all the struts interview questions and answers..

Leave a comment

Spam protection by WP Captcha-Free