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

Search Java Interview Questions


 2098 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' - 92 question(s) found - Order By Newest

 Q1. If you are given a choice to implement the code to either Insert a Record or Update if already exist, Which approach will you follow ?

1. Insert into the DB Table. If exception occurs, update the existing record.
2. Check if the record exists and update it if it exists, If not insert a new record.
Solution
admin
info@buggybread.com
Ans. In first case, there would be 2 DB calls in worst case and 1 in best case. In 2nd approach there will be always 2 DB calls.

Decision on the approach should depend on the following considerations -

1. How costly is the call to DB ? Are we using indices , hibernate etc

If calls to DB are costly , 1st approach should be the choice.

2. Exception Book keeping load upon exception.

The benefit of saving 1st call in approach 1 should be bigger than the Book keeping for the exception.

3. Probability of the exception in first apparoach.

If the DB Table is almost empty, it makes sense to follow Approach 1 as majority of the 1st calls will pass through without exception.

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

   Like      Discuss      Correct / Improve     database   insert-update   db exceution plan   db strategy   design   architecture   technical lead


Almost sure to be asked in every company using any Dependency Injection framework ( Spring, Guice etc )
  Q2. 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


 Q3. In which cases , moving methods to utility class could be useful ?Core Java

Ans. It could be worthy to move a method to util class if the method needs to be shared, doesn't require polymorphic behavior and need not be overridden in special cases.

Don't belong to one group through is-a relationship ( You can share through parent class method )

Don't implement a specific interface ( java 8 default methods )

Doesn't involve complex computing as you will be loosing the benefit of object state with just static method.

Doesn't require polymorphic behavior as static methods don't participate in runtime polymorphism.

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

   Like      Discuss      Correct / Improve     utility classes   util classes   static methods   application design        rare


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


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


 Q6. 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.
  Q7. 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


 Q8. What is the difference between these two approaches of creating singleton Class ?

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

//Single checked locking code
public static Singleton createInstance() {
   synchronized(Singleton.class) {
      if(singleton == null) {
         singleton = new Singleton();
      }
   }
   return singleton;
}
Design
Admin
info@buggybread.com
Ans. In First Case , Lock for the synchronized block will be received only if singleton == null whereas in second case every thread will acquire the lock before executing the code.
The problem of synchronization with singleton will only happen when the object has not be instantiated. Once instantiated , the check singleton == null will always generate true and the same object will be returned and hence no problem. First condition will make sure that synchronized access ( acquiring locks ) will only take place if the object has not been created so far.

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

   Like      Discuss      Correct / Improve     java   singleton   synchronization

Try 1 Question(s) Test


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



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



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


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


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


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


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


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


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


 Q17. What is a Listener ?Design
Anonymous
Ans. In GUI programming, an object that can be registered to be notified when events of some given type occur. The object is said to listener? for the events.

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

   Like      Discuss      Correct / Improve     java   gui   ui programming   swing   awt   swt   listener   architecture


 Q18. What are use cases?Process
Admin
info@buggybread.com
Ans. It is part of the analysis of a program and describes a situation that a program might encounter and what behavior the program should exhibit in that circumstance.

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

   Like      Discuss      Correct / Improve     use cases   design   high level design   testing   test driven development   software system analyst   project lead      basic        frequent


Very frequently asked. Usually followed by questions related to private constructor and synchronized access. Frequently asked in JPMorgan (Based on 2 feedback)
  Q19. 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      intermediate        frequent



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. Shouldn't we make a class with all static members is its just expected to be executed as a standalone program with just one thread. Moreover Lets assume that there is no runtime Polymorphism required and there is no need for serialization ?Design
Admin
info@buggybread.com
Ans. Still No in case we are making use of inheritance. we may have problem wherein we have program flow moving across common inherited method and specific methods of the derived class. call made to another static method in the parent class will only access the static class of the Parent class irrespective of the call from any of the derived class.

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

   Like      Discuss      Correct / Improve     static class   static vs singleton   inheritance


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


 Q22. Which UML diagrams you usually use for design ?Design
Admin
info@buggybread.com
Ans. Use Case Diagram, Component Diagram for High level Design and Class Diagram , Sequence Diagram for low level design.

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

   Like      Discuss      Correct / Improve     software system analyst   development lead   project lead   technical lead   technical architect      expert        frequent


 Q23. What kind of software architecture your organization follow ?Design
Admin
info@buggybread.com
Ans. We have multi tier architecture with multiple layers , We have series of web servers and applications in application tier, infrastructure libraries at middle tier and Database servers at the lower tier. We are using Oracle as Database, ESB ( Enterprise service Bus ) for asynchronous communication and Rest Web Services.

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

   Like      Discuss      Correct / Improve     software system analyst   development lead   project lead   technical lead   technical architect


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


 Q25. What are the fail safe systems ?Operating System2016-06-09 09:29:43

Ans. Fail Safe systems are tolerant systems that continue processing even if they sense any problem. the objective here is to continue with the processing even if there are some problems instead of completely shutting it down. Example could be to catch an exception and still letting it complete with partial results.

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

   Like      Discuss      Correct / Improve     fail safe systems   system design   exception handling     Verilogue


 Q26. Explain TDD or Test Driven Design ?Design

Ans. TDD is a development process that involves short iterations: first an automated test case is written. Then, the code is written to pass that test, and finally one refactors the new code to acceptable standards.

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

   Like      Discuss      Correct / Improve     elsevier   test driven design ( TDD )   software development methodologies     Elsevier  Deegit  Cerner        frequent


Frequently asked in face to face interviews.
  Q27. Write a program to print fibonacci series.Core Java

Ans. int count = 15;
int[] fibonacci = new int[count];
fibonacci[0] = 0;
fibonacci[1] = 1;
for(int x=2; x < count; x++){
fibonacci[x] = fibonacci[x-1] + fibonacci[x-2];
}

for(int x=0; x< count; x++){
System.out.print(fibonacci[x] + " ");
}

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

   Like      Discuss      Correct / Improve     ebay   fibonacci series     Manvish eTech  Belvedere Trading  King UK  FinaTel  Goldman Sachs  Enlighten Software  Misys  Mahindra Comviva  ZapCom  Nucleus Software Exports  Enlighten  Sears  Mahindra Satyam  Insperity  General Motors  AVIS e Solutions  Paddy Power Betfair  TurningCloud  Polestar Solutions  BlueWhale Solutions  CitiusTech  Zuhlke  Comcast  KGFSL  Quickr  Paramatrix Technologies  CalSoft  Ancestry.com  OnMobile Global  NBCUniversal  Inventum Technologies  Hughes Systique  Flextronics  Geometric Soft  Check Point Software Technologies  ZapLabs  Indecomm Global Services  HTC Global  Quovantis Technologies  Mobiloitte  Riktam Technologies  DMX Technologies  Mojo Networks  Tata Elxsi  Ciena  ServiceNow  EverBridge  LendingClub  Virtusa Polaris  West Corporation  Ebay  Walmart  HomeAway  AllClear ID  Quinnox Software  Acquity Group  Cadence Design Systems  SmartPrix  Leidos  Zoho  Varian Medical Systems  HealthSparq      basic        frequent


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


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



 Q30. What are the fail fast systems ?2016-06-09 09:31:27

Ans. Fail fast systems are intolerant systems that fails at the first instance of smelling any problem. The objective here is to break the system instead of continuing with the possibly flawed processing. Example could be breaking the processing upon an exception.

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

   Like      Discuss      Correct / Improve     fail fast systems   system design     Verilogue


 Q31. If you are given a choice to have a functionality shared either through dependency or through a Web service, which one will you choose ?Solution2016-06-13 10:38:53

Ans. Web Service promotes looser coupling but with comes with coding and performance overheads. Jars provide better performance and may be lesser coding but are problematic with update distribution. If the situation doesn't require frequent dependency updates and if it's only read operation of persistence, Having dependencies should be a better choice , otherwise web service.

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

   Like      Discuss      Correct / Improve     Design  Web Service vs Jar


Frequently asked for Lead and Architect positions. Recently asked in many US companies.
  Q32. 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


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


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


 Q35. Can Enum be a replacement for a constant file in majority of the situation ?Design2016-08-11 16:21:25

Ans. Yes , it can be but it may not be an optimal alternative if we need to change the values frequently. As Enum is compiled like any Java File , any change requires the application to be rebuild , deployed and restart.

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

   Like      Discuss      Correct / Improve     enum  design


 Q36. Write a class explaining builder pattern ?Design2016-08-17 10:32:03

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


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


 Q38. Design a Library system ?Design2016-10-21 11:26:36

Ans. Following Tables can be created

ASSET - Entity Table With foreign key reference to Table AssetType

ASSET_TYPE - Entity Table specifying information related to Asset Type like Books, CDs etc.

MEMBER - Registration information for the member

MEMBERSHIP_TYPE - Membership Types provided by Library

MEMBERSHIP - Relation table with foreign key for MEMBER ,

MEMBERSHIP_TYPE

ASSET_ISSUE_LEDGER - Relationship between MEMBER and ASSET. This specify the issue of particular asset to a particular member.

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

   Like      Discuss      Correct / Improve     design     Vivint


Frequently asked Design Pattern interview question.
 Q39. 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



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q40. What are the advantages disadvantages of keeping config entries in database instead of property file and vice versa ?Design2016-11-14 11:33:09

Ans. Entries in DB will be retrieved at runtime unless a cache is maintained in application. Entries in File will be loaded to memory by default. Both can be implemented in 1 manner or other. By default property file will take space in memory, will be faster, and will require application restart on change. By Default DB config will be pulled at runtime, will be little slower, and doesn't require an application restart.

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

   Like      Discuss      Correct / Improve     design


 Q41. Have you ever felt the need of keeping the constructor private ?Design2016-11-15 09:40:58

Ans. Yes, When either we don't want an object to be created ( class having all static elements and hence not required ) or object to be created using a static method or static block. One such example could be a situation when we would like app to load objects at start up and we would like to restrict new object creation by any request.

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

   Like      Discuss      Correct / Improve     private constructor  constructor


 Q42. Is it a Good practice to have application decision making in DAOs ?Design2016-11-15 09:43:40

Ans. No, DAO's should only have methods to perform CRUD operations. Application logic should reside in service methods.

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

   Like      Discuss      Correct / Improve     A


  Q43. What is coupling and Cohesion ?Design2016-11-15 16:16:10

Ans. Coupling is the degree of interdependence between software modules, a measure of how closely connected two modules are or the strength of the relationships between modules.

Cohesion refers to the degree to which the elements of a module belong together. Cohesion measures the strength of relationship between pieces of functionality within a given module.

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

   Like      Discuss      Correct / Improve     coupling  cohesion     State Farm  EPAM  Vanguard  Incedo  Maverick  B2 Solutions  At&T  Datto  HCL Technologies  Xactly        frequent


 Q44. Can you please provide an implementation of application level cache ?Design2016-11-18 13:42:22

Ans. We can use an expiration map whose entries gets expired after a certain interval and then we can put the logic to retrieve the entries if its expired in map. Alternatively we can create a separate class and make map its element. We can refresh the map in this class periodically by using a monitoring thread within static block.

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

   Like      Discuss      Correct / Improve     


 Q45. What is a responsive web design ?Design2016-11-21 15:20:37

Ans. Responsive web design is a approach to web design that allow desktop webpages to be viewed perfectly in different devices and sizes.

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

   Like      Discuss      Correct / Improve          American Express


Very Frequently asked to Senior Software Engineers or Developers.
  Q46. 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


 Q47. Design an online shopping site system ?Design2016-12-13 11:06:10

 This question was recently asked at 'Alibaba'.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          Alibaba


 Q48. Implement an LRU Cache ?Design2016-12-13 14:46:01

 This question was recently asked at 'Myntra'.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          Myntra


 Q49. Design a Data Structure for a full text Search ?Design2016-12-13 14:47:02

 This question was recently asked at 'Myntra'.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          Myntra



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



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


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


 Q52. Write a program to print two digit numbers that fulfil following criteria

Summing their digits and then multiplying with 3 should result in the number

For ex - 27 , (2+7) * 3 = 27


Core Java2017-01-28 11:20:28

Ans. public class BuggyBread {
   public static void main(String args[]) {
      for(int x=10;x<100;x++){
         int tensDigit = x/10;
         int unitDigit = x%10;
         
         if((tensDigit+unitDigit)*3 == x){
            System.out.println(x);
         }
      }
   }
}

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

   Like      Discuss      Correct / Improve          Internet Design Zone


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


 Q54. How would you do an object oriented design on animals in a zoo ?Design2017-02-03 13:14:47

 This question was recently asked at 'Booking.com,InterContinental Hotels,Caissa,Workday'.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          Booking.com  InterContinental Hotels  Caissa  Workday


 Q55. Design a Passport Office systemDesign2017-02-11 13:58:33

 This question was recently asked at 'Netcracker Technology'.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     Netcracker Technology


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


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


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


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



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q60. Is it a good Design practice to call methods from a constructor ?Design2017-03-10 10:21:53

Ans. Constructor's objective is to initialize member elements. If we don't deviate from that and don't have methods with logic in them, I don't see an issue with constructor's calling other methods assuming the methods are doing nothing but initialization. There are situations wherein we classify the member elements based on their type and hence having different initialization methods for different element types will give a better abstracted way to initialize them.

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

   Like      Discuss      Correct / Improve     design constructor


 Q61. Is it a good design practice to have programming constructs like if and loops in constructor ?Design2017-03-10 10:24:04

Ans. I would avoid that. If we need to initialize member elements differently on the basis of some condition, I would prefer having overloaded constructors. I don't see a need to have a loop for initializing member elements unless the count of elements is huge and they all need to be initialized with common value.

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

   Like      Discuss      Correct / Improve     design constructor


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


 Q63. Why it's a good practice to expose member elements through getter methods ?Design2017-03-10 10:54:10

Ans. Encapsulation and Polymorphism.

We need methods to access variables in a polymorphic way as overriding only happens with methods and not with variables. Moreover getter provides a way to minimally open the access window for the object and hence provides better encapsulation. To add to those, we can have validation in the getter method before returning elements.

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

   Like      Discuss      Correct / Improve     encapsulation


 Q64. What should be the intended sequence in which elements and methods should be declared in a class ?Design2017-03-10 10:55:09

Ans. static final variables
public variables ( though it should be avoided )
private variables
constructor
public methods
private methods.

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

   Like      Discuss      Correct / Improve     


 Q65. Is it a good practice to override static methods ?Design2017-03-10 10:58:02

Ans. Though it's useful but it's not as useful as overriding member or object methods. We cannot achieve polymorphic behavior with static methods by overriding their definition in derived class.

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

   Like      Discuss      Correct / Improve     override static methods


 Q66. How do you prefer to keep names for classes and interfaces ?Design2017-03-10 10:59:51

Ans. I like to keep the names in Capital Camel case. Moreover I prefer to keep the names for classes, enums and interfaces such that they are easily distinguishable just by the pattern of their names.

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

   Like      Discuss      Correct / Improve     naming convention


 Q67. How can we prevent duplicate object creation in Java?Design2017-03-25 10:34:30

 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     


 Q68. Create an object oriented design using classes and interfaces to show relationship in a Sport tournament ?Design2017-03-25 10:35:52

 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     


 Q69. What is "convention over configuration" ? Which framework uses this design paradigm ?Design2017-05-06 08:14:46

Ans. Convention over configuration is a way of software design used by frameworks that attempt to decrease the number of decisions that a developer is required to make without necessarily losing flexibility. The objective is to reduce the unnecessary configurations and follow conventions to accomplish that. For example - DB Entity and DB Table name conventionally should be same and hence shouldn't require configuring mapping between the two.

"Spring Boot" and "Ruby on Rails" have adopted this design principle.

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

   Like      Discuss      Correct / Improve     Convention over configuration     VMware



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q70. Are there any disadvantages of "Convention over configuration" Design paradigm ?Design2017-05-06 08:17:15

Ans. Yes, It may result in some loss of flexibility as the application has to follow all conventions. Moreover it can contradict with other design paradigms or principles used in the application or framework.

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

   Like      Discuss      Correct / Improve     Convention over configuration


 Q71. Can you give an example of "Convention over configuration" Design principle ?Design2017-05-06 08:20:19

Ans. Hibernate mapping configurations are used for mapping hibernate entities and corresponding DB Tables. Conventionally Entities and Table can share the same name and hence framework can provide implicit mapping instead of explicit mapping through configurations. Though it may result in little loss of flexibility in extreme cases but will work with all applications following the convention.

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

   Like      Discuss      Correct / Improve     Convention over configuration


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


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


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


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


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


 Q77. Design a Coffee machine using Oops concepts.Design2017-06-13 20:26:14

 This question was recently asked at 'ECI Telecom'.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  design a coffee machine     ECI Telecom


 Q78. Give an example of how Object Oriented Programming Concepts can be implemented.Design2017-06-18 06:45:37

 This question was recently asked at 'Accenture'.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     oops  oops example  oops concepts  oops features     Accenture      basic        frequent


 Q79. What are the benefits of Dependency Injection or IOC ?Design2017-06-23 11:51:20

 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     dependency injection  IOC  inversion of control



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q80. Design a class diagram for a farm.Design2017-07-07 13:27:04

 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     class diagram   design


 Q81. What are the worst anti patterns in Java ?Design2017-07-23 20:09:44

 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


 Q82. If you need to consume messages from the queue faster, which approach will you recommend - batching or concurrency ?Design2017-07-24 13:34:47

Ans. Each has it's own advantages

Batching requires less resources but may result in loosing whole batch in case of failure whereas concurrency even though is little more expensive in terms of resources but would result in minimal loss in case of failure.

In case messages are to be consumed in a particular order, batching them in that order and then consuming them makes better sense.

if incoming messages are not continuous , it makes more sense to do concurrency as we need not wait for all messages to form a batch and flush. Though time sensitivity can be added but that would add unnecessary complexity.

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

   Like      Discuss      Correct / Improve     concurrency vs batching   concurrency  multithreading  batch


 Q83. How can we track of all objects created in an application ?Design2017-08-04 14:02:03

Ans. We can store the references in a collection by adding to those objects in the collection. We can create a class "ObjectRegistry" with a collection or multiple collections with a search algorithm to look for the already collected objects.

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

   Like      Discuss      Correct / Improve     objects


 Q84. Let's suppose we have an to destroy objects, Design a program to implement garbage collection ?Design2017-08-04 14:08:01

Ans. Step 1 - We can create a Registry Class having Map of all created objects as key and References list as value.

Step 2 - Whenever we create an object , we should update the Registry in the constructor to add the new object.

Step 3 - Whenever we assign a new reference to the object , we need to update the entry in Map. Similarly if the reference get's removed ( end of scope etc ), we need to remove the entry of reference from the list.

Step 4 - We can have threaded code to monitor the Map to see if any object looses all it's references and should call the method to destroy object and clean the memory.

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

   Like      Discuss      Correct / Improve     garbage collection


 Q85. Which of the OOP's features facilitate dependency injection ? Design2017-08-06 19:11:22

Ans. Inheritance , Runtime Polymorphism and Composition.

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

   Like      Discuss      Correct / Improve     dependency injection  inversion of control  ioc  oops  oops features


 Q86. Is dependency injection possible if we don't have inheritance / Composition ?Design2017-08-06 19:13:37

Ans. Without composition - No, as it's the core of dependency injection.

With Inheritance - Yes, through interface implementation.

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

   Like      Discuss      Correct / Improve     dependency injection  inversion of control  ioc


 Q87. How do you design microservices?Design2017-08-14 20:19:54

 This question was recently asked at 'Citigroup 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     microservices     Citigroup Bank


 Q88. What could be the driving force to have dependencies injected through class than through config file while using IOC or Dependency Injection ? Design2017-08-18 09:45:24

Ans. Unit Testing

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

   Like      Discuss      Correct / Improve     dependency injection  inversion of control


 Q89. Design a Database Schema to store Employee Information with each employee having multiple addresses. Database2017-08-24 13:48:56

Ans. We can have 2 entities i.e EMPLOYEE and ADDRESS and can have a relationship Table , EMPLOYEE_ADDRESS having one to may relationship between the two.

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

   Like      Discuss      Correct / Improve     database schema   design     Accenture


 Q90. Which of the following class types in MVC should have Business Logic ?Design
a. Model
b. View
c. Controller
d. JSP

Ans.a. Model

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

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

2 person from are looking for questions for 'Design'. Connect with them to better prepare for your interview.Click here and post a message

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: