These are set of Java Design pattern both core and J2EE questions which you could expect in an interview. Question are both beginner to advanced level.

  1. Do the need of DTO exists in the EJB 3 and up ?
    The one of the main reason that give birth to the DTOs was entity beans were not selialized in earlier specification of EJB. Which made DTO a good candidate to carry data from and to between the different layers of the application. However EJB 3 's entity beans can be serializable making DTOs an unnecessary addition. However it still can be used when we need more of an assember than just a transfer object.
  2. What is the difference between Value Object and DTO ?
    A Value Object was mostly confused to be a DTO, however they are differnt,  A value Object is immutable, once created can not be modified,and one more important distiction is it two value objects are  equal based on the value they bear, not if they are the same object ( reference). A value object represents a String like currency symbol, a name of a product etc. On the other hand a DTO is serializable , and mutable. To understand a value object better, lets take an example , if you were given 5 hunderd dollar bills, you would consider these notes as same , 5 hunderd dollar bill
  3. What is the disadvantage of DTO pattern ?
    The DTO pattern is used to simplify the data access to the View layer,but problems that might arise it when a change is required in the domain model , we need to reflect it on the view layer , the domain model itself and our DTO. And since DTOs are tend to dumb objects ( no logic, only setters and getters ) it could be an overhead than a use,now that we have EJB3 with entity beans ( domain models ) serializable.DTOs can be considered highly overkill.

    Questions on Singleton Pattern
  4. In how many ways can you create singleton pattern ?
    There are few famous ways you can create singleton objects .
    Lazy loading
    eager loading
  5. Write a test class that your unsynchronised singleton implementation is giving you more than one different instances.
  6. If the singletons getInstance is not synchronized ( case of lazy loading ) , does it guarentee it would give you maximum of two instances of singleton class in an multithreaded environment?
    No, Threads can be unpredictable , we can't guarentee when the method is unsynchronized it would give max of two singleton instance.

Questions on Factory Pattern