Tags

Jan 24, 2012

Design patterns for Java Interview


Before you appear for an interview, be ready with 8-10 design patterns with examples from your projects and be confident to answer questions about how you implemented those design patterns. Here I am providing a list of some common design patterns which a candidate can talk about in a Java interview.

1) Flyweight: As discussed above, it’s a part of JDK and hence is used by every Java program.
2) Iterator: All collection classes provide the feature of an iterator to iterate their elements. Moreover, I have also seen custom classes in my projects where the feature of iterator is custom built for those classes.
3) DAO (Data Access Object) : This is also one of the common design pattern seen in many applications which use SQL commands to interact with the datasource/database. Usually a DAO class has methods which invoke the SQL queries for CRUD operations on the database tables thus avoiding the need to write and maintain SQL queries in multiple classes for the same database tables.

4) DTO (Data Transfer Object) : This design pattern represents the data which is actually stored in the database tables in terms of Java classes and is accepted as argument by various methods of the DAO classes. This design pattern usually translates to POJO classes corresponding to database tables and their columns.
5) Factory: If you have used DAO then it is very likely that you have also seen factory design pattern being used as a factory class is written for generating the DAO’s.
6) Abstract Factory: This design pattern represents a factory of factories. When you have many closely related factory classes, you will write an interface which all those factories implement and thus can be generically referenced. You will write a class which will have methods to return the appropriate factory depending upon the need.
7) MVC: This is also one of the famous design patterns and should not be missed in Java interview.
8) Front Controller: This design pattern is closely associated with MVC design pattern and is used to write the single point of contact for any request that comes from the users. The controller then dispatches the request to appropriate handler depending upon the arguments being passed along with the request.
9) Singleton: Though Singleton design pattern looks to be easy to understand and get away with any Java interview but one can be grilled like anything on this design pattern. There is so much to ask on Singleton that a candidate can be judged only by asking questions on Singleton. This is because the interviewer can associate Inheritance, Reflection, Serialization, Collections, Polymorphism, Cloning and other Java concepts with Singleton.
Still if you were to choose only five design patterns for an interview due to time constraints then I would advise the following list:
1) Singleton
2) DAO (Data Access Object)
3) DTO (Data Transfer Object)
4) MVC (Model View Controller)
5) Factory


3 comments:

  1. Great Info! What you have provided. It is very informative.Interview Questions

    ReplyDelete
  2. Hi Stectek,
    Thanks for visiting my blog.

    ReplyDelete
  3. This content is helpful for the freshers who are new to the job market.The freshers will be surfing for the question which will be asked in the process of interview!Love this blog!
    Questions

    ReplyDelete