Java - Interview Questions and Answers for 'Design pattern' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2137 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Design pattern' - 40 question(s) found - Order By Newest

Almost sure to be asked in every company using any Dependency Injection framework ( Spring, Guice etc )
  Q1. What is Dependency Injection or IOC ( Inversion of Control ) ?Design

Ans. It is a Design Pattern that facilitates loose coupling by sending the dependency information ( object references of dependent object ) while building the state of the object. Objects are designed in a manner where they receive instances of the objects from other pieces of code, instead of constructing them internally and hence provide better flexibility.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     design patterns   ioc ( Inversion of Control )  dependency injection     Nucleus Software Exports  HCL Technologies  Tata Consultancy (TCS)  HCL  Infosys  Cognizant (CTS)  Barclays  General Electric  Infosys Technologies  Elsevier  Sabre  ZapCom  Nike  Sogeti  CSG International  Lowes  DWS  Mitsui Bussan Logistics  Payment Processing Partners  Liquidnet  AmTrust Financial  VectorForm  Cybage  Vanderbilt University  Cigniti  Accenture  Ball Aerospace  GE Healthcare  1-800 Contacts  VinSolutions  Arrow Electronics  Monitise  Avenue Code  Thetus Corporation  Shodogg  Levi9  BuildLinks  Suyati Technologies  Kanerika Software  Alliance Inspection Management  Promega  Victorious  Zoll Data Systems  Parkmobile  PerceptiMed  Crate and Barrel  Carbonite  Concur  Codazen  GlobalLogic  AccuSoft  Attinad  Tillster  AppRiver  TrustPilot  Pearson  Kony  Art Technology Group  VeriSign  Accion Labs  IGS Energy  National Bankruptcy Services  RealPage  Green Dot  Indecomm Global  bebo Technologies  Open Solutions  Xoriant  NCR  Macmillan Cancer Support  NetSuite  Asynchrony Labs  DealDash  Vizio  Fiserv  Federal Reserve Bank of Minneapolis  Tinder  FICO  Trustwave      intermediate        frequent


 Q2. What are the Wrapper classes available for primitive types ?Core Java
Anonymous
Ans. boolean - java.lang.Boolean
byte - java.lang.Byte
char - java.lang.Character
double - java.lang.Double
float - java.lang.Float
int - java.lang.Integer
long - java.lang.Long
short - java.lang.Short
void - java.lang.Void

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   java5   data types   wrapper classes   adapter design pattern        rare


 Q3. What Design pattern Wrapper Classes implement ?Design
Anonymous
Ans. Adapter.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   wrapper classes   adapter design pattern   design pattern


 Q4. Difference between Factory and Abstract Factory Design Pattern ?Design
Anonymous
Ans. Factory Pattern deals with creation of objects delegated to a separate factory class whereas Abstract Factory patterns works around a super-factory which creates other factories.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   design pattern   factory design pattern   abstract factory design pattern   technical lead      expert


Very frequently asked.Usually among first few questions.
  Q5. What is MVC ? Design
Anonymous
Ans. The Model/View/Controller pattern, a strategy for dividing responsibility in a GUI component.

The model is the data for the component.

The view is the visual presentation of the component on the screen.

The controller is responsible for reacting to events by changing the model.

According to the MVC pattern, these responsibilities should be handled by different objects.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     j2ee   mvc   mvc design pattern   design pattern   struts   spring   web application   web frameworks   ebay     HCL Technologies  Tata Consultancy (TCS)  Wipro  United Health Group (UHG)  Accenture  Fidelity  Fidelity Investments   Tieto  Walt Disney  Sharon Software Systems  Tech Mahindra  Amdocs  Deegit  Lexis Nexis  Elsevier      basic        frequent

Try 1 Question(s) Test


 Q6. Difference between Factory and Builder Design Pattern ?Design
Anonymous
Ans. Builder pattern is the extension of Factory pattern wherein the Builder class builds a complex object in multiple steps.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   design pattern   factory design pattern   builder design pattern      expert


 Q7. Difference between Proxy and Adapter ?Design
Anonymous
Ans. Adapter object has a different input than the real subject whereas Proxy object has the same input as the real subject. Proxy object is such that it should be placed as it is in place of the real subject.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   design pattern   proxy   adapter      expert


 Q8. Difference between Adapter and Facade ?Design
Anonymous
Ans. The Difference between these patterns in only the intent. Adapter is used because the objects in current form cannot communicate where as in Facade , though the objects can communicate , A Facade object is placed between the client and subject to simplify the interface.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   design pattern   adapter   facade      expert


 Q9. Difference between Builder and Composite ?
Anonymous
Ans. Builder is a creational Design Pattern whereas Composite is a structural design pattern. Composite creates Parent - Child relations between your objects while Builder is used to create group of objects of predefined types.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   design pattern   builder   composite   creational design pattern   structural design pattern



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. Example of Chain of Responsibility Design Pattern ?
Anonymous
Ans. Exception Handling Throw mechanism.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   design pattern   chain of responsibility      expert


 Q11. Example of Observer Design Pattern ?
Anonymous
Ans. Listeners.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   design pattern   listeners   observer design pattern      expert


 Q12. Difference between Factory and Strategy Design Pattern ?Design
Anonymous
Ans. Factory is a creational design pattern whereas Strategy is behavioral design pattern. Factory revolves around the creation of object at runtime whereas Strategy or Policy revolves around the decision at runtime.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   design pattern   factory   strategy   creational design pattern   behavioral design pattern     Alibaba      expert


 Q13. Shall we use abstract classes or Interfaces in Policy / Strategy Design Pattern ?
Anonymous
Ans. Strategy deals only with decision making at runtime so Interfaces should be used.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   design pattern   strategy design patterm      expert


 Q14. What are different types of dependency injections ?Design 2017-11-07 09:37:47

Ans. Setter injection
Constructor injection
Interface injection
Look-up method/method injection

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     dependency injection   design patterns     IBM


Very frequently asked. Usually followed by questions related to private constructor and synchronized access. Frequently asked in JPMorgan and TCS (Based on 2 feedback)
  Q15. Explain Singleton Design Pattern ?Design
Admin
info@buggybread.com
Ans. http://www.buggybread.com/2014/03/java-design-pattern-singleton-interview.html

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   design pattern   singleton   at&t   ebay  fidelity india  united healthcare india     JP Morgan  Tata Consultancy (TCS)  HCL Technologies  Wipro  Infosys  Tibco  Edline  JPMorgan Chase  Sabre  Bank Of America India  Fidelity  Samsung India  Robert Bosch India  ZapCom  Goldman Sachs India  Eze Software  ZapCom  Dailymotion  Netflix  CenturyLink  Misfit  TSYS  ECI Telecom  Dealogic  Robert Bosch  Redolent  EFI  CSX  Prolific  Validus  Birlasoft  AdNovum  NCR  Ray Business Technologies  Nagravision  Unify  SLK Group  DBS Bank   Razorthink  GST Global  USAA  Ray Technologies  Ray Business Technologies (Raybiztech)  Raybiztech      intermediate        frequent


 Q16. Give an Example for Builder Pattern ?Core Java
Admin
info@buggybread.com
Ans. String str = new StringBuilder().append("Buggy").append("Bread").toString();

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   builder pattern   design pattern   stringbuilder   string     Power System Consultants (PSC)  Xactly Corp  BetterCloud

Try 1 Question(s) Test


 Q17. Which of the following is not the difference between Singleton and Static class ( Class with static members only ) ?

a. Only one object can be created for Singleton class whereas No objects are created for static class.
b. Singleton class instance is initiated using new keyword whereas static class instance is created using static method.
c. Singleton class can be serialized whereas Static class cannot be.
d. Singleton Class can participate in runtime Polymorphism whereas Static class cannot.
Anonymous
Ans. Singleton class instance is initiated using new keyword whereas static class instance is created using static method.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   singleton   design pattern   static class


 Q18. Write code for singleton classDesign

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?keyword=singleton+class&category=code

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     singleton  code  coding  design pattern     ECI Telecom      Intermediate        frequent


 Q19. Write code for the usage of Builder Design Pattern

Ans. http://javasearch.buggybread.com/CodeSnippets/searchCodeSamples.php?&category=code&searchOption&keyword=964

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     builder design pattern  builder pattern  code  coding      intermediate



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



Frequently asked for Lead and Architect positions. Recently asked in many US companies.
  Q20. What are Anti Patterns ?Design2016-07-14 14:21:11

Ans. Anti-pattern is simply the creation of a pattern in your coding that negatively affects your code i.e the Negatives surpasses the positives.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     anti patterns  design patterns     JP Morgan  Zoftech Systems  Winter Court Consulting  Tripsta  Travelplanet24  The Big Game Hunter  Pardot  Randstad  Addison        frequent


 Q21. What are design situations to use Singleton and Prototype Design Pattern ?Design2016-07-28 20:28:43

Ans. Both are creational design patterns.

Singleton is used when we would like to reuse an object if object is not supposed to hold request or thread specific information. Inversely Prototype is used in situations where we would like to reuse the object information but the request / thread may require it own data to be persisted.

In short, Singleton is used in situations where we can live with single object being shared across multiple requests or threads whereas Prototype is used when we need duplicate copies of objects.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     design pattern  singleton  prototype  creational design pattrn     Mphasis  JP Morgan  Fidelity  EPAM  Airline Tariff  Vimukti Technologies  Cardinal Health      expert

Try 1 Question(s) Test


 Q22. Does it make sense to clone an object which is supposed to be immutable ?Design2016-07-28 20:54:59

Ans. It make sense only if we intend to modify either of the object and would like to preserve original state in other. Otherwise we can reuse the original object by making it singleton.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     clone  clone objects  prototype design pattern


 Q23. What are the advantages and disadvantages of Factory Design Pattern ?Design2016-09-07 09:19:26

Ans. Object Oriented Design Patterns is the science of identifying the pattern to make objects communicate in a way to effectively implement a Solution.

Factory Design Patterns is the pattern that recommends creation of separate Factory Object for creation of other object. So its like saying - If you want to create an object of ClassA, Talk to FactoryObject ( which is an object of FactoryClass ). FactoryObject in itself encapsulates the inputs and logic required to make the decision regarding the creation and construction of object.

Advantage of Factory Pattern - Loose Coupling and Segregation of Responsibilities. Now instead of hard binding the complete logic to decide the nature and shape of the object on the basis of some conditions, you are assigning the responsibility to some other object and hence making the relationship loosely coupled and hence main tenable.

Disadvantages - Before Understanding the Dis-advantages , we should understand that these patterns were chosen after a period of evolution and research and almost best fit for the required solution, otherwise these patterns would have easily been replaced by now.

Though the advantages of these pattern surpass the disadvantages keeping in mind the decreasing cost of resources and increasing scale of applications, but still loose coupling by means of additional objects results in decreased performance.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     factory design pattern  design pattern


Frequently asked Design Pattern interview question.
 Q24. What is a prototype design pattern ?Design2016-11-04 08:06:01

Ans. The prototype pattern is a creational design pattern. It is used when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. Prototype is used when we need duplicate copies of objects.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     design pattern  prototype design pattern     CapitalOne  Orion Edutech  Harris  Myntra  Tata Consultancy (TCS)  HCL Technologies  Infosys  Wipro  Tech Mahindra  IBM  Mahindra Satyam      intermediate


Very Frequently asked to Senior Software Engineers or Developers.
  Q25. Describe some of the Design Patterns you have used ?Design2016-12-01 16:31:17

Ans. [Open Ended Answer]

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     design patterns     Goldman Sachs  Lexis Nexis  Elsevier  HCL Technologies  Tata Consultancy (TCS)  Infosys Technologies  Fidelity Investments  Nucleus Software Exports  General Electric  Cognizant (CTS)  Amdocs  MathWorks  Xebia  Goldstone technologies  Horizon Solutions  ECI Telecom      intermediate        frequent


 Q26. How to make sure that only one instance is created in Singleton Pattern ?Core Java2016-12-21 10:00:04

Ans. By Using Double Checked Locking code

//Double Checked Locking Code
public static Singleton createInstance() {
if(singleton == null){
synchronized(Singleton.class) {
if(singleton == null) {
singleton = new Singleton();
}
}
}
return singleton;
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     singleton  design pattern     Bank Of America India


 Q27. What is a factory design pattern ?Design2017-01-09 13:21:43

Ans. Factory Design Patterns is the pattern that recommends creation of separate Factory Object for creation of other object. So its like saying - If you want to create an object of ClassA, Talk to FactoryObject ( which is an object of FactoryClass ). FactoryObject in itself encapsulates the inputs and logic required to make the decision regarding the creation and construction of object.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     design pattern  factory design pattern     EPAM  EMC  TMP Worldwide  Sapient  Ernst & Young (EY)   ThyssenKrupp Materials  Wipro  Scotiabank


 Q28. Difference between Singleton and Factory Design Pattern ?Design2017-02-02 11:24:01

Ans. Both are creational design patterns but singleton facilitates in creation and reuse of single object whereas Factory deals with creation of multiple objects.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Design pattern  singleton  factory  singleton vs factory     Jabong.com  Intuit  Kumaran Systems  BirlaSoft


 Q29. Name few creational design patterns ?Design2017-02-12 16:06:15

Ans. Factory,Abstract Factory,Singleton,Prototype and Builder

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Design Pattrns  Creational Design Patterns      Intermediate



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q30. Name few structural Design Patterns ?Design2017-02-12 16:07:00

Ans. Adapter,Bridge,Composite,Decorator,Facade,Flyweight,Proxy

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Design Patterns  Structural Design Patterns      Intermediate


 Q31. Name few Behavioral Design Patterns ?Design2017-02-12 16:07:59

Ans. Interpreter,Chain of Responsibility,Command,Iterator,Observer,Mediator,Memento

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Behavioral Design Patterns      Intermediate


 Q32. Which is your favorite Design pattern, each in Creational , Structural and Behavioral and Why ?Design2017-02-12 16:08:45

Ans. [Open Ended Answer]

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Design Patterns      Intermediate


 Q33. Which are the most commonly used Design Patterns ?Design2017-03-10 10:42:50

Ans. Builder ( While Writing Unit Tests )
Prototype ( Cloning )
Adapter ( asList , toString )
Chain Of Responsibility ( Logging )
Singleton
Factory ( Action Mapping )
Proxy
Observer ( Event Listener )
MVC ( Web frameworks )
Filter ( Criteria )

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Design Patterns  widely used Design patterns      intermediate        frequent

Try 1 Question(s) Test


 Q34. Explain Interceptor Design Pattern ?Design2017-05-06 19:23:08

Ans. It is used for intercepting the request. It's primary use is to implement security policy. All or specific request types can be intercepted and hence forwarded to authentication / authorization module so as to facilitate authorized requests to application.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     interceptors  interceptor design pattern


 Q35. What are some uses of interceptors ?Java EE2017-05-06 19:26:02

Ans. Authentication / Authorization
URL forwarding
Auditing / Logging
Localization

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     interceptors  interceptor design pattern


 Q36. What are the disadvantages of Adapter Design Pattern ?Design2017-05-07 08:43:19

Ans. It introduces a layer of adaptations before it reaches the final and desired interface.

Moreover sometimes all requests are forwarded to adapter class. Some of such requests doesn't even require any sort of adaptions as they are qualified to call the final interface directly and introducing overheads.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Adapter Design Pattern  design pattern


 Q37. What could be the real world example of Adapter Design Pattern ?Design2017-05-07 08:45:07

Ans. Voltage converters / Power Adapters

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     Adapter Design Pattern  Design Pattern


 Q38. What are the trade offs between public constructor and static final method ?Core Java2017-05-07 19:26:45

Ans. Public constructor is simple and easy as it's the default way of object creation. So there are no additional coding overheads as compiler provides the default constructor if none is provided by coder.

With static final methods, it facilitates loose coupling by segregating the responsibility of object creation to a separate method. Validation can be done on the constructor arguments before calling it. Moreover if any adaption on the arguments is required that can achieved easily with factory method.On the flip side, there is coding overhead and additional method call.

  Sample Code for constructor

  Sample Code for factory

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     constructor  factory design pattern  factory method


 Q39. Listeners are example of ..Design
a. Factory design Pattern
b. Abstract Factory Design Pattern
c. Singleton Design Pattern
d. Observer Design Pattern

Ans.d. Observer Design Pattern

 Q40. Which of the following Design pattern has been used with Hibernate Criteria ?Hibernate
a. Filter
b. Prototype
c. Builder
d. Observer

Ans.a. Filter



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: