Posted by
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.
- How will you design your Singleton Patten class to be thread-safe? (a standard interview question!)
- What Design Pattern can be used for classical Producer Consumer problem? (a simple question)
- 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?
- 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?
- 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?
- 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?
- 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:
Related posts brought to you by Yet Another Related Posts Plugin.
Nice questions. the book you mentioned is old, right? where can i get examples for design patterns in Java?
Hi,
whenever you post interview questions, please post the answers too.
Thanks
Deepak.
hi mani i wud lik to knw the ans for those qs..cud u pl send dem to ..itsrkk@gmail.com
@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.
Nice questions.
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
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
hi mani,if u have more Q’s on design patterns keep posted…
thankz anyway for the ans’s
we expect more frm u.
@rkk: thanks
Sure, will post more on that.
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 …
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
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…
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
hi rkk,
will be posting it periodically.
sure. but, i need enough time to write big posts
thanks
Thank for sharing.
hi mani this rellay nice answer of the question.
could you please provide the more scenario means
question and answer.
Thanks
Raj
Hi Mani,
I came across your blog today. Nice blog
i have a question ..which design pattend does log 4j use?