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

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

   
Frequently asked for Lead and Architect positions. Recently asked in many US companies.
  Q31. What are Anti Patterns ?Design
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     Asked in 9 Companies        frequent


 Q32. Does it make sense to clone an object which is supposed to be immutable ?Design
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   immutable  immutability  immutability  cloning


 Q33. Write a class explaining builder pattern ?Design
Ans.
public class BuggyBread { 

private String element1;

private String element2;

private BuggyBread(String element1, String element2){
this.element1 = element1;
this.element2 = element2;
}

public static class Builder {

private String element1;

private String element2;

Builder(BuggyBread buggybread){
element1 = buggybread.element1;
element2 = buggybread.element2;
}

Builder withElement1(String element1){
this.element1 = element1;
return this;
}

Builder withElement2(String element2){
this.element2 = element2;
return this;
}

BuggyBread build(){
BuggyBread buggybread = new BuggyBread(element1,element2);
return buggybread;
}
}
}


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

   Like         Discuss         Correct / Improve     builder pattern  builder class

Try 1 Question(s) Test


Frequently asked Design Pattern interview question.
 Q34. What is a prototype design pattern ?Design
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  cloning     Asked in 11 Companies      intermediate


 Q35. How to make sure that only one instance is created in Singleton Pattern ?Core Java
Ans. public class SingleTon {
private SingleTon() {
if (singleTon != null) {
throw new RuntimeException("cant not create the object");
}
}
public Object clone() throws CloneNotSupportedException {
throw new CloneNotSupportedException("can not be create");
}

static private volatile SingleTon singleTon;
public static SingleTon getInstance() {
SingleTon singleTon = this.sample;
if (singleTon == null) {
synchronized (this) {
singleTon = this.singleTon;
if (singleTon == null) {
singleTon = this.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     Asked in 2 Companies


 Q36. What is a factory design pattern ?Design
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     Asked in 9 Companies


 Q37. Difference between Singleton and Factory Design Pattern ?Design
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     Asked in 4 Companies


 Q38. Name few creational design patterns ?Design
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


 Q39. Name few structural Design Patterns ?Design
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


 Q40. Name few Behavioral Design Patterns ?Design
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


 Q41. Which is your favorite Design pattern, each in Creational , Structural and Behavioral and Why ?Design
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


 Q42. Which are the most commonly used Design Patterns ?Design
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


 Q43. Explain Interceptor Design Pattern ?Design
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


 Q44. What are the disadvantages of Adapter Design Pattern ?Design
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


 Q45. What could be the real world example of Adapter Design Pattern ?Design
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


 Q46. What are the trade offs between public constructor and static final method ?Core Java
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


 Q47. What are the worst anti patterns in Java ?Design
 This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     antipattern  anti pattern


 Q48. How one dao Implementation object (singleton) can handle multiple requests?Design Pattern
 This question was recently asked at 'Capgemini'.This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     singleton     Asked in 1 Companies


 Q49. Explain Facade design patternDesign
Ans. Single gateway of the entire application is called Facade Design Pattern.

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

   Like         Discuss         Correct / Improve     design pattern  facade     Asked in 1 Companies


 Q50. What is the difference between Observer and Subscriber ?Design
 This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     Design Patterns


 Q51. Design a Program to clone an object and all it's children.
Design
 This question was recently asked at 'Bloomberg'.This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     code  coding  cloning  design pattern   cloning design pattern     Asked in 1 Companies


 Q52. Draw uml for singleton pattern.Design
 This question was recently asked at 'deutche bank'.This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     design pattern   singleton     Asked in 1 Companies


 Q53. What is MVC in GUI components ?Design
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     mvc  design pattern     Asked in 1 Companies        rare


 Q54. If you have to pull a sub string out of a string, which method would you use - using String methods or Pattern / Matcher ?Design
Ans. It depends on how complex it is and if in future it would need any sort opf debugging. It's not easy to debug code if it's making heavy use of shortcuts like Lambda , Patterns etc.

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

   Like         Discuss         Correct / Improve     pattern matching  String  design


 Q55. Design pattern used in struts.Struts
Ans. Struts controller uses the Command design pattern and the action classes use the Adapter design pattern. The process() method of the RequestProcessor uses the Template method design pattern.

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

   Like         Discuss         Correct / Improve     Struts Design patterns     Asked in 1 Companies


 Q56. With the following code, Which is a valid way to initialize ?
public class BuggyBread {

   private String element1;

   private String element2;

   private BuggyBread(String element1, String element2){
      this.element1 = element1;
      this.element2 = element2;
   }

   public static class Builder {
   
      private String element1;

      private String element2;

      Builder(BuggyBread buggybread){
         element1 = buggybread.element1;
         element2 = buggybread.element2;
      }

      Builder withElement1(String element1){
         this.element1 = element1;
         return this;
      }

      Builder withElement2(String element2){
         this.element2 = element2;
         return this;
      }

      BuggyBread build(){
         BuggyBread buggybread = new BuggyBread(element1,element2);
         return buggybread;
      }
   }
}
Core Java
a. BuggyBread buggybread = new BuggyBread();
b. BuggyBread buggybread = new BuggyBread("element1","element2");
c. BuggyBread.Builder builder = new BuggyBread.Builder();
d. BuggyBread.Builder builder = new BuggyBread.Builder("element1","element2");

Ans.d. BuggyBread.Builder builder = new BuggyBread.Builder("element1","element2");

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

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

Ans.a. Filter

previous 30   

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: