Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share
Help Us Improve. Please share your interview experience.
Company Name:
Questions Asked:
         
 Would like to receive new questions directly to your email as a weekly digest.
Enter your email address:
Top Contributors

vinay( vinay.putta458@gmail.com)
Prabhakar(kumar12abhakar@gmail.com)
Ameera(amiratalzain94@gmail.com)
Manoj()
Harish(harish.wheeler@gmail.com)

Search Java Interview Questions


 1682 questions in repository. 21003 searches in last week.
Label / Company      Label / Company / Text

   



Interview Question and Answers - 1682 question(s) found

next 100
Very frequently asked. Among the first few questions in many interviews.Among Top 10 frequently asked questions.
  Q1. Difference between == and .equals() ?Core Java
Anonymous
Ans. "equals" is the method of object class which is supposed to be overridden to check object equality, whereas "==" evaluate to see if the object handlers on the left and right are pointing to the same object in memory.

x.equals(y) means the references x and y are holding objects that are equal. x==y means that the references x and y have same object.


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

   Like      Discuss     java   string comparison   string   object class   ==    equals   object equality     Ebay  Cerner  GuideWire  Expeditors Associate  Revature  SAIC  ValueLabs  Realty Redefined  Bank Of America  Capgemini  HCL Technologies  Goldman Sachs  Symmetric Corp  Backstop Solutions  Frontier Science  Vanguard  eClinicalWorks  Experticity  Blue Cross and Blue Shield of Kansas  ComTrade  Banja Luka  Overstock.com  Intrasoft International  IBM      basic        frequent

Try 6 Question(s) Test


Advanced level question. Usually asked in High end product companies.
  Q2. Why is String immutable in Java ?Core Java
Anonymous
Ans. 1. String Pool - When a string is created and if it exists in the pool, the reference of the existing string will be returned instead of creating a new object. If string is not immutable, changing the string with one reference will lead to the wrong value for the other references.

Example -

String str1 = "String1";
String str2 = "String1"; // It doesn't create a new String and rather reuses the string literal from pool

// Now both str1 and str2 pointing to same string object in pool, changing str1 will change it for str2 too

2. To Cache its Hashcode - If string is not immutable, One can change its hashcode and hence it's not fit to be cached.

3. Security - String is widely used as parameter for many java classes, e.g. network connection, opening files, etc. Making it mutable might possess threats due to interception by the other code segment.

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

   Like      Discuss     java   oops   string   string class   immutable   advanced     Barclays  Jungo  Cloudera  Allston  Man Group  Prokarma  Optimus  Gamesys  ABS  TransPerfect  Fidelity  Deloitte  Zalando  Cognizant (CTS)  Zeta Interactive  SuccessFactors   EchoStar  InterGlobe Technologies  HCL Technologies  Intuit  JP Morgan  Optimus Information  Faichi Solutions  Blip  Adobe  Subex Limited  Remo Software  Allstate  IBM  Bizmatics      expert        frequent

Try 4 Question(s) Test


Very frequently asked in different variations. Frequently asked in Deloitte ( 2 feedback ) , HCL Tech ( 3 feedback ) and Coginizant (CTS)
  Q3. Explain the scenerios to choose between String , StringBuilder and StringBuffer ?Core Java
Anonymous
Ans. If the Object value will not change, use String Class because a String object is immutable.

If the Object value can change and will only be modified from a single thread, use StringBuilder because StringBuilder is unsynchronized(means faster).

If the Object value may change, and can be modified by multiple threads, use a StringBuffer because StringBuffer is thread safe(synchronized).

  Sample Code for String

  Sample Code for StringBuffer

  Sample Code for StringBuilder

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

   Like      Discuss     java   string class   string   stringbuilder   stringbuffer     Cognizant (CTS)   San Jose State University (SJSU)  HCL Technologies   Deloitte  Sophos  Hitachi  JPMorgan Chase  IBM  Kony Labs  Keystone      basic        frequent

Try 3 Question(s) Test


Frequently asked to fresh graduates and less experienced developers. Among the first few questions in many interviews.
  Q4. What are the difference between composition and inheritance in Java?Core Java
Admin
info@buggybread.com
Ans. Composition - has-a relationship between classes.
Inheritance - is-a relationship between classes.

Composition - Composing object holds a reference to composing classes and hence relationship is loosely bound.
Inheritance - Derived object carries the base class definition in itself and hence its tightly bound.

Composition - Used in Dependency Injection
Inheritance - Used in Runtime Polymorphism

Composition - Single class objects can be composed within multiple classes.
Inheritance - Single class can only inherit 1 Class.

Composition - Its the relationship between objects.
Inheritance - Its the relationship between classes.

  Sample Code for inheritance

  Sample Code for composition

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

   Like      Discuss     java   java concepts   inheritance   composition   inheritance vs composition     HCL Technologies  Tata Consultancy (TCS)  Infosys  Amazon  Source Intelligence  News UK  Starmount  MapQuest  SalesForce  Expedia  Deegit  JP Morgan  Canva  Todle  Yodle  Berkley Net  Help Scout  Partners HealthCare  Doximity  Commvault  Heroku  Starmount  Help.com  healthcare system  TU Kaiserslautern      basic        frequent

Try 5 Question(s) Test


 Q5. Which are the different segments of memory ?Core Java
Anonymous
Ans. 1. Stack Segment - Contains primitives, Class / Interface names and references.

2. Heap Segment - Contains all created objects in runtime, objects only plus their object attributes (instance variables), Static variables are also stored in heap.

3. Code Segment - The segment where the actual compiled Java bytecodes resides when loaded

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

   Like      Discuss     java   memory   memory management   stack memory   heap memory   code segment memory   advanced     NX Developer  Velocity  Commvault  eBizprise Taiwan      expert        frequent

Try 6 Question(s) Test


 Q6. What are points to consider in terms of access modifier when we are overriding any method?Core Java
Admin
info@buggybread.com
Ans. 1. Overriding method can not be more restrictive than the overridden method.

reason : in case of polymorphism , at object creation jvm look for actual runtime object. jvm does not look for reference type and while calling methods it look for overridden method.

If by means subclass were allowed to change the access modifier on the overriding method, then suddenly at runtime when the JVM invokes the true objects version of the method rather than the reference types version then it will be problematic

2. In case of subclass and superclass define in different package, we can override only those method which have public or protected access.

3. We can not override any private method because private methods can not be inherited and if method can not be inherited then method can not be overridden.

  Sample Code for Overriding

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

   Like      Discuss     java   overriding   access specifier   inheritence   oops   polymorphism   runtime polymorphism     Genpact

Try 2 Question(s) Test


 Q7. Why do we need Inner classes ? Cant we just work with outer classes wherever we implement Inner classes ?Core Java
Admin
info@buggybread.com
Ans. Yes, we can substitute outer classes wherever we need to have inner classes but Inner classes have advantage in certain cases and hence preferred -

Ease - Why to implement a class outside if its objects are only intended to be part of an outer object. Its easy to define the class within another class if the use is only local.

Protection - Making a call an outer exposes a threat of it being used by any of the class. Why should it be made an outer class if its object should only occur as part of other objects.

For example - You may like to have an class address whose object should have a reference to city and by design thats the only use of city you have in your application. Making Address and City as outer class exposes City to any of the Class. Making it an inner class of Address will make sure that its accessed using object of Address.

  Sample Code for inner class

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

   Like      Discuss     java   inner classes   classes   objects   technical lead      intermediate

Try 1 Question(s) Test


 Q8. What are different ways of object creation in Java ?Core Java
Admin
info@buggybread.com
Ans. Using new operator - new xyzClass()

Using factory methods - xyzFactory.getInstance( )

Using newInstance( ) method - (Class.forName(xyzClass))emp.newInstance( )

By cloning an already available object - (xyzClass)obj1.clone( )

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

   Like      Discuss     java   oops   object creation   new operator   class.forname   cloning   ebay     Intelligrape  Infosys  Polaris  British Telecom (BT)  Vyom Labs  Deutsche Bank      expert


 Q9. What are different ways to create String Object? Explain.Core Java
Admin
info@buggybread.com
Ans.
String str = new String("abc");
String str1 = "abc";


When we create a String using double quotes, JVM looks in the String pool to find if any other String is stored with same value. If found, it just returns the reference to that String object else it creates a new String object with given value and stores it in the String pool.

When we use new operator, JVM creates the String object but dont store it into the String Pool. We can use intern() method to store the String object into String pool or return the reference if there is already a String with equal value present in the pool.

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

   Like      Discuss     java   string class   string   jvm   memory management   string pool     GuideWire  NTT Data  Fractal Analytics      basic        frequent

Try 3 Question(s) Test



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. What do you mean by "Java is a statically typed language" ?Core Java
Admin
info@buggybread.com
Ans. It means that the type of variables are checked at compile time in Java.The main advantage here is that all kinds of checking can be done by the compiler and hence will reduce bugs.

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

   Like      Discuss     java   statically typed language   variable declaration      basic        frequent


 Q11. What are the common uses of "this" keyword in java ?Core Java
Anonymous
Ans. "this" keyword is a reference to the current object and can be used for following -

1. Passing itself to another method.

2. Referring to the instance variable when local variable has the same name.

3. Calling another constructor in constructor chaining.

  Sample Code for this keyword

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

   Like      Discuss     java   this   object reference   constructor chaining      intermediate        rare

Try 3 Question(s) Test


 Q12. Does garbage collection guarantee that a program will not run out of memory?Core Java
Anonymous
Ans. Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection

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

   Like      Discuss     java   garbage collection   java memory management   advanced

Try 1 Question(s) Test


Frequently asked.
 Q13. If you are given a choice to use either ArrayList and LinkedList, Which one would you use and Why ?Core Java
Admin
info@buggybread.com
Ans. ArrayList are implemented in memory as arrays and hence allows fast retrieval through indices but are costly if new elements are to be inserted in between other elements. LinkedList allows for constant-time insertions or removals using iterators, but only sequential access of elements
1. Retrieval - If Elements are to be retrieved sequentially only, Linked List is preferred.
2. Insertion - If new Elements are to be inserted in between other elements , Array List is preferred.
3. Search - Binary Search and other optimized way of searching is not possible on Linked List.
4. Sorting - Initial sorting could be pain but lateral addition of elements in a sorted list is good with linked list.
5. Adding Elements - If sufficiently large elements needs to be added very frequently ,Linked List is preferable as elements don't need consecutive memory location.

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

   Like      Discuss     java   collections   list   arraylist   linkedlist   difference between   architecture   data structure   ebay      basic        frequent

Try 2 Question(s) Test


Frequently asked question in companies using Hibernate.
  Q14. What is Lazy Initialization in Hibernate ?Hibernate
Admin
info@buggybread.com
Ans. It's a feature to lazily initialize dependencies , relationship and associations from the Database. Any related references marked as @OneToMany or @ManyToMany are loaded lazily i.e when they are accessed and not when the parent is loaded.

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

   Like      Discuss     hibernate   lazy loading hibernate   lazy initialization hibernate   architecture     overstock.com  BridgePoint Technologies  Medgate  Dex Media  Diversant  Tieto  Oracle  Bank of America Merrill LYNCH  NEC Japan      Basic        frequent

Try 2 Question(s) Test


  Q15. What is a Lambda Expression ? What's its use ?Core Java
Admin
info@buggybread.com
Ans. Its an anonymous method without any declaration.

Lambda Expression are useful to write shorthand Code and hence saves the effort of writing lengthy Code.

It promotes Developer productivity, Better Readable and Reliable code.

  Sample Code for lambda

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

   Like      Discuss     java   java8   lambda expression   architecture     Axxess  CACI  ZonOff  Dell India  Wellington Management  N26  Lithium Technologies      expert        frequent

Try 1 Question(s) Test


 Q16. Which of the following combination of keywords is illegal in Java ?

a. static and transient
b. transient and final
c. static and synchronized
d. abstract and final
Core Java
Anonymous
Ans. abstract and final

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

   Like      Discuss     java   java keywords     VirtusaPolaris  IVTL InfoView Technologies      basic


 Q17. How can we run a java program without making any object?Core Java
Anonymous
Ans. By putting code within static method. With Java 6 and earlier versions, even static block can be used.

  Sample Code for static block

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

   Like      Discuss     java   oops   static   static method   static block     American Express  Cognizant (CTS)      basic        frequent

Try 1 Question(s) Test


 Q18. What are the benefits of JSON over XML ?Json
Anonymous
Ans. Lighter and faster than XML as on-the-wire data format

Object Representation - Information is presented in object notations and hence better understandable.

Easy to parse and conversion to objects for information consumption.

Support multiple data types - JSON supports string, number, array, boolean whereas XML data are all string.

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

   Like      Discuss     json   markup language     QualiTest      intermediate        frequent

Try 1 Question(s) Test


 Q19. Can we use both "this()" and "super()" in a constructor ?Core Java
Anonymous
Ans. No, because both this and super should be the first statement.

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

   Like      Discuss     java   oops  this   super   constructor      intermediate        rare

Try 2 Question(s) Test



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q20. What are the ways to avoid LazyInitializationException ?Hibernate
Admin
info@buggybread.com
Ans. 1. Set lazy=false in the hibernate config file.

2. Set @Basic(fetch=FetchType.EAGER) at the mapping.

3. Make sure that we are accessing the dependent objects before closing the session.

4. Force initialization using Hibernate.initialize

5. Using Fetch Join in HQL.

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

   Like      Discuss     hibernate   lazy loading hibernate   lazy initialization hibernate   lazyinitializationexception   architecture

Try 2 Question(s) Test


 Q21. Why every object constructor automatically call super() in Object before its own constructors?Core Java
Admin
info@buggybread.com
Ans. Derived object carries the body of its class as well as the body of the parent class. Its body ( member elements ) is initialized using its own class constructor whereas the body ( member elements ) carried from the parent class are initialized using super class constructor. So In order to initialize the elements of the parent class before its own elements are even initialized, super is called.

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

   Like      Discuss     java   oops   constructor   super   inheritance   inheritence      intermediate


 Q22. What is the difference between declaration, instantiation and initialization ?Core Java2016-05-26 14:17:48

Ans. Declaration is intimation to the compiler about the nature of Data a reference is going to hold.

For example - List myList;

Instantiation is reservation of memory.

For example

myList = new ArrayList();

Initialization or construction is setting the default values for member elements.

For example

myList = new ArrayList(mySet);

** Example 2nd is both for instantiation as well as initialization. The only difference is that 2nd will initialized the member elements to their default values whereas 3rd will initialized it with the elements from set.


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

   Like      Discuss     declaration   instantiation   initialization   construction      basic        frequent


Very frequently asked to Fresh graduates.
  Q23. What is difference between Encapsulation And Abstraction?Core Java
Anonymous
Ans. 1.Abstraction solves the problem at design level while encapsulation solves the problem at implementation level

2.Abstraction is used for hiding the unwanted data and giving relevant data. while Encapsulation means hiding the code and data into a single unit to protect the data from outside world.

3. Abstraction lets you focus on what the object does instead of how it does it while Encapsulation means hiding the internal details or mechanics of how an object does something.

4.For example: Outer Look of a Television, like it has a display screen and channel buttons to change channel it explains Abstraction but Inner Implementation detail of a Television how CRT and Display Screen are connect with each other using different circuits , it explains Encapsulation.

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

   Like      Discuss     java   oops   oops concepts   encapsulation   abstraction   basic interview question     Synechron  Amazon  HCL Technologies  Tata Consultancy (TCS)  Wipro  Infosys Technologies      basic        frequent

Try 2 Question(s) Test


Very frequently asked. Favorite question in Walk in Drive of many Indian service companies.
  Q24. What is the difference between final, finally and finalize() ?Core Java
Admin
info@buggybread.com
Ans. final - constant variable, restricting method overloading, restricting class sub classing.

finally - handles exception. The finally block is optional and provides a mechanism to clean up regardless of what happens within the try block. Use the finally block to close files or to release other system resources like database connections, statements etc.

finalize() - method helps in garbage collection. A method that is invoked before an object is discarded by the garbage collector, allowing it to clean up its state.

  Sample Code for final

  Sample Code for finally

  Sample Code for finalize

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

   Like      Discuss     java   oops   final   finally   finalize     Thomson Reuters  WITS  Antra  Jive  MorningStar  VanGuard   Alcatel Lucent  Morningstar  A9.com  EPAM  Nuance  SirsiDynix  NCR  VanGuard  Proofpoint Interview  Disney  Orbitz Worldwide  GFI Informatique  Canon  WITS  Simba Technologies  Marlabs  American Well  Global Relay  L&T Infotech  HCL Technologies  Tata Consultancy (TCS)  Wipro  Infosys  Accenture  Jive  Salesforce  Deegit  NTT DATA  Proofpoint  Morningstar  Bank Of America  Manhattan Associates  Optum  NorthPoint  Nok Nok Labs  Simba Technologies   Rhino Africa  Solutionreach  V Soft Consulting  EBay  Cognizant (CTS)  IBM  ExactTargetKewill  CV Holdings  Symphony  Cubic Web solutions  Star International  FatWire  Mindteck      basic        frequent

Try 4 Question(s) Test


 Q25. What is session tracking and how do you track a user session in servlets?Java EE
Admin
info@buggybread.com
Ans. Session tracking is a mechanism that servlets use to maintain state about a series requests from the same user across some period of time. The methods used for session tracking are:

User Authentication - occurs when a web server restricts access to some of its resources to only those clients that log in using a recognized username and password

Hidden form fields - fields are added to an HTML form that are not displayed in the client's browser. When the form containing the fields is submitted, the fields are sent back to the server

URL rewriting - every URL that the user clicks on is dynamically modified or rewritten to include extra information. The extra information can be in the form of extra path information, added parameters or some custom, server-specific URL change.

Cookies - a bit of information that is sent by a web server to a browser and which can later be read back from that browser.

HttpSession- places a limit on the number of sessions that can exist in memory.

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

   Like      Discuss     j2ee   servlets   session   session management   web applications   cookies   httpsession   url rewriting   architecture     Infosys


Very frequently asked. Favorite question in Walk in Drive of many Indian service companies.
  Q26. Difference between TreeMap and HashMap ?Core Java
Anonymous
Ans. They are different the way their elements are stored in memory. TreeMap stores the Keys in order whereas HashMap stores the key value pairs randomly.

  Sample Code for treemap

  Sample Code for hashmap

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

   Like      Discuss     java   collections   map   treemap   hashmap     Amber Road  CTS (Cognizant)  ION Trading  DataMetica  Accenture  The Advisory Board Company  BidGely  Infosys  Tata Consultancy (TCS)  HCL Technologies  Wipro  Booking.com  MakeMyTrip  Garena Online  Garmin  ION Trading  Accuity  Palantir Technologies  Books International  Wealthfront  Marin Software  Garmin  IBM  Global Logic  Fiserv  Cumulus Systems  CCTS      basic        frequent

Try 1 Question(s) Test


 Q27. What will this code print ?

String a = new String ("TEST");
String b = new String ("TEST");
if(a == b) {
System.out.println ("TRUE");
} else {
System.out.println ("FALSE");
}
Core Java
Anonymous
Ans. FALSE. == operator compares object references, a and b are references to two different objects, hence the FALSE. .equals method is used to compare string object content.

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

   Like      Discuss     string   string class   java   ==   object references   coding      basic        frequent

Try 1 Question(s) Test


Frequently asked. Favorite question in Walk in Drive of many Indian service companies.
  Q28. What are the methods of Object Class ?Core Java
Anonymous
Ans. clone() - Creates and returns a copy of this object.

equals() - Indicates whether some other object is "equal to" this one.

finalize() - Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

getClass() - Returns the runtime class of an object.

hashCode() - Returns a hash code value for the object.

toString() - Returns a string representation of the object.

notify(), notifyAll(), and wait() - Play a part in synchronizing the activities of independently running threads in a program.

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

   Like      Discuss     java   oops   object class     Capgemini  NIIT Technologies   Virtusa  Goldman Sachs  PwC  Citi  Expeditors  SoftFluent  LinkedIn  Amadeus  Navteq  PLC Systems  Axtria Associate  Netcracker Technology  Altisource      basic        frequent

Try 1 Question(s) Test


Recently asked in Accenture and Fidelity.
 Q29. Explain Flow of Spring MVC ?Spring
Admin
info@buggybread.com
Ans. The DispatcherServlet configured in web.xml file receives the request.

The DispatcherServlet finds the appropriate Controller with the help of HandlerMapping and then invokes associated Controller.

Then the Controller executes the logic business logic and then returns ModeAndView object to the DispatcherServlet.

The DispatcherServlet determines the view from the ModelAndView object.

Then the DispatcherServlet passes the model object to the View.

The View is rendered and the Dispatcher Servlet sends the output to the Servlet container.

Finally Servlet Container sends the result back to the user.

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

   Like      Discuss     j2ee   spring   mvc   frameworks   web applications   architecture     Accenture  fidelity      Basic        frequent



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



Advanced level question frequently asked in US based companies. Recently asked in EMC and Intuit.
  Q30. Can you provide some implementation of a Dictionary having large number of words ? Solution
Admin
info@buggybread.com
Ans. Simplest implementation we can have is a List wherein we can place ordered words and hence can perform Binary Search.

Other implementation with better search performance is to use HashMap with key as first character of the word and value as a LinkedList.

Further level up, we can have linked Hashmaps like ,

hashmap {
a ( key ) -> hashmap (key-aa , value (hashmap(key-aaa,value)
b ( key ) -> hashmap (key-ba , value (hashmap(key-baa,value)
....................................................................................
z( key ) -> hashmap (key-za , value (hashmap(key-zaa,value)
}

upto n levels ( where n is the average size of the word in dictionary.

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

   Like      Discuss     java   collections   hashmap   binary search   search algorithm   advanced   architecture   data structure     Dell EMC   Intuit   Corporate Brokers  PWC India  Yahoo  Oracle        frequent

Try 1 Question(s) Test


Frequently asked to experienced developers. Recently asked in many US interviews.
 Q31. What is database deadlock ? How can we avoid them?Database
Admin
info@buggybread.com
Ans. When multiple external resources are trying to access the DB locks and runs into cyclic wait, it may makes the DB unresponsive.

Deadlock can be avoided using variety of measures, Few listed below -

Can make a queue wherein we can verify and order the request to DB.

Less use of cursors as they lock the tables for long time.

Keeping the transaction smaller.



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

   Like      Discuss     java   database   architecture     MSCI  Vudu  Bank Of America  Sears      expert        frequent


Very frequently asked. Favorite question in Walk in Drive of many Indian service companies.
  Q32. What is the difference between ArrayList and LinkedList ?Core Java
admin
info@buggybread.com
Ans. Underlying data structure for ArrayList is Array whereas LinkedList is the linked list and hence have following differences -

1. ArrayList needs continuous memory locations and hence need to be moved to a bigger space if new elements are to be added to a filled array which is not required for LinkedList.

2. Removal and Insertion at specific place in ArrayList requires moving all elements and hence leads to O(n) insertions and removal whereas its constant O(1) for LinkedList.

3. Random access using index in ArrayList is faster than LinkedList which requires traversing the complete list through references.

4. Though Linear Search takes Similar Time for both, Binary Search using LinkedList requires creating new Model called Binary Search Tree which is slower but offers constant time insertion and deletion.

5. For a set of integers you want to sort using quicksort, it's probably faster to use an array; for a set of large structures you want to sort using selection sort, a linked list will be faster.

  Sample Code for ArrayList

  Sample Code for LinkedList

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

   Like      Discuss     collections   java   data structures   arraylist   linkedlist     Deutsche Bank  Overstock.com  HCL Technologies  Infosys  EBay  The Advisory Board Company  Accuity  JC Penney  Cerner  Chase  Amazon  Deloitte  Deegit  Tata Consultancy  Cognizant (CTS)  IBM  Accenture  Mindtree  ESRI  QwikCilver Solutions  TMC Bonds  GumGum  EMC  Yelp  Classteacher Learning System  FactSet  Simply Hired  SalesForce  Royall & Company  Indeed  eClinicalWorks  TravelClick  State Farm  Manhattan Associates  GoEuro  Veeva Systems  Ness Technologies  Marlabs  Rolta  Volante Technologies  Happiest Minds Technologies  Coviam  Velocify  zanox  SimplyHired  IDBI Intech  Wissen Infotech  Nike  OnDot  PexSupply  Pramati Technologies  Credit Agricole  Mastek  Six Dee Telecom  Accuity  Kellton Tech      Basic        frequent

Try 1 Question(s) Test


 Q33. Which keyword is used to provide explicit access of a code block to single thread ?

a. Transient
b. Final
c. Explicit
d. Synchronized
Core Java
Anonymous
Ans. Synchronized

  Sample Code for Synchronized

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

   Like      Discuss     java   threads   multithreading     Infoview


 Q34. What are different types of classes ?Core Java

Ans. There are different verticals in which Java Classes can be classified.

1. Access - Public , Private , default or Protected.

2. Packaging - System, library or User Defined

3. Structure - Outer or Inner

4. Object Derivation - Abstract Class or Concrete Class.

5. Object Creation - Normal, Singleton , Doubleton , Immutable or Enum.

6. Functionality - String , Util , Stream etc.

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

   Like      Discuss     classes   different types of classes     iFactor

Try 1 Question(s) Test


 Q35. Can you give a real world example of Encapsulation and Abstraction ?Core Java2016-05-29 13:47:31

Ans. Car Engine is an example of encapsulation and abstraction. You ignite the car using an interface called starter and least bothered about how the tire actually moves (This is abstraction). The engine encapsulates the complete process to itself only and doesn't allow you to start the other components like the radiator etc ( this is excapsulation )

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

   Like      Discuss     encapsulation  abstraction  oops  oops features  java features     MAQ Software  Daffodil Software  Quickstart Global  Alliance Global Services  InfoStretch  Intelligrape  Prowareness  Support.com  Cognizant (CTS)  BNT SOFT  Clairvoyant TechnoSolutions  Suyati Technologies


 Q36. What are concepts introduced with Java 5 ?Core Java
Anonymous
Ans. Generics , Enums , Autoboxing , Annotations and Static Import.

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

   Like      Discuss     java   java5   generics   enum   autoboxing   annotations   static import        rare

Try 1 Question(s) Test


 Q37. Describe what happens when an object is created in Java ?Core Java
Anonymous
Ans. 1. Memory is allocated from heap to hold all instance variables and implementation-specific data of the object and its superclasses. Implemenation-specific data includes pointers to class and method data.
2. The instance variables of the objects are initialized to their default values.
3. The constructor for the most derived class is invoked. The first thing a constructor does is call the constructor for its superclasses. This process continues until the constructor for java.lang.Object is called,as java.lang.Object is the base class for all objects in java.
4. Before the body of the constructor is executed, all instance variable initializers and initialization blocks are executed. Then the body of the constructor is executed. Thus, the constructor for the base class completes first and constructor for the most derived class completes last.

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

   Like      Discuss     java   memory management   object creation   advanced   ebay


Advanced level question usually asked in High end product companies. Have been asked in Google and Amazon (Based on 1 Feedback)
  Q38. Describe, in general, how java's garbage collector works ?Core Java
Anonymous
Ans. The Java runtime environment deletes objects when it determines that they are no longer being used. This process is known as garbage collection. The Java runtime environment supports a garbage collector that periodically frees the memory used by objects that are no longer needed. The Java garbage collector is a mark-sweep garbage collector that scans Java dynamic memory areas for objects, marking those that are referenced. After all possible paths to objects are investigated, those objects that are not marked (i.e. are not referenced) are known to be garbage and are collected.

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

   Like      Discuss     java   garbage collection   java memory management   advanced     LinkedIn  Infosys  Google  Netflix  Amazon  Huawei Technologies  JP Morgan  enGenius  CitiusTech  Goldman Sachs  Bank Of America India  Salesforce  Addteq  Criteo  Capgemini      intermediate        frequent

Try 4 Question(s) Test


 Q39. What is JDBC? Describe the steps needed to execute a SQL query using JDBC.Database
Anonymous
Ans. The JDBC is a pure Java API used to execute SQL statements. It provides a set of classes and interfaces that can be used by developers to write database applications.

The steps needed to execute a SQL query using JDBC:

1. Open a connection to the database.
2. Execute a SQL statement.
3. Process th results.
4. Close the connection to the database.

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

   Like      Discuss     java   jdbc   db connectivity     Nucleus Software Exports      basic        frequent



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q40. Are constructors inherited? Can a subclass call the parent's class constructor? When?
Anonymous
Ans. You cannot inherit a constructor. That is, you cannot create a instance of a subclass using a constructor of one of it's superclasses. One of the main reasons is because you probably don't want to override the superclasses constructor, which would be possible if they were inherited. By giving the developer the ability to override a superclasses constructor you would erode the encapsulation abilities of the language.

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

   Like      Discuss     java   oops   constructor   inheritence      expert        rare

Try 1 Question(s) Test


 Q41. Can we access instance variables within static methods ?Core Java
Anonymous
Ans. Yes.we cannot access them directly but we can access them using object reference.Static methods belong to a class and not objects whereas non static members are tied to an instance. Accessing instance variables without the instance handler would mean an ambiguity regarding which instance the method is referring to and hence its prohibited.

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

   Like      Discuss     java   oops   static   static methods   java keywords     Oracle


 Q42. What are the benefits of using Spring Framework ?Spring
Admin
info@buggybread.com
Ans. Spring enables developers to develop enterprise-class applications using POJOs. The benefit of using only POJOs is that you do not need an EJB container product.

Spring is organized in a modular fashion. Even though the number of packages and classes are substantial, you have to worry only about ones you need and ignore the rest.

Spring does not reinvent the wheel instead, it truly makes use of some of the existing technologies like several ORM frameworks, logging frameworks, JEE, Quartz and JDK timers, other view technologies.

Testing an application written with Spring is simple because environment-dependent code is moved into this framework. Furthermore, by using JavaBean-style POJOs, it becomes easier to use dependency injection for injecting test data.

Spring’s web framework is a well-designed web MVC framework, which provides a great alternative to web frameworks such as Struts or other over engineered or less popular web frameworks.

Spring provides a convenient API to translate technology-specific exceptions (thrown by JDBC, Hibernate, or JDO, for example) into consistent, unchecked exceptions.

Lightweight IoC containers tend to be lightweight, especially when compared to EJB containers, for example. This is beneficial for developing and deploying applications on computers with limited memory and CPU resources.

Spring provides a consistent transaction management interface that can scale down to a local transaction

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

   Like      Discuss     java   spring framework   mvc   spring container   architecture   technical architect   java architect   technical lead  ioc     MasterCard


Advanced level question. Recently asked in few Indian service companies ( Based on 3 inputs )
 Q43. What are various types of Class loaders used by JVM ?Core Java
Admin
info@buggybread.com
Ans. Bootstrap - Loads JDK internal classes, java.* packages.

Extensions - Loads jar files from JDK extensions directory - usually lib/ext directory of the JRE

System - Loads classes from system classpath.

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

   Like      Discuss     java   jvm   memory management   class loaders   bootstrap   extensions   system  classloaders   advanced   technical lead   technical architect     Deloitte  Mindtree  Accenture  Synechron


  Q44. Difference between SAX and DOM Parser ?Xml
Admin
info@buggybread.com
Ans. A DOM (Document Object Model) parser creates a tree structure in memory from an input document whereas A SAX (Simple API for XML) parser does not create any internal structure.

A SAX parser serves the client application always only with pieces of the document at any given time whereas A DOM parser always serves the client application with the entire document no matter how much is actually needed by the client.

A SAX parser, however, is much more space efficient in case of a big input document whereas DOM parser is rich in functionality.

Use a DOM Parser if you need to refer to different document areas before giving back the information. Use SAX is you just need unrelated nuclear information from different areas.

Xerces, Crimson are SAX Parsers whereas XercesDOM, SunDOM, OracleDOM are DOM parsers.

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

   Like      Discuss     java   xml   parsers   sax   dom parser   difference   architecture   technical lead   technical architect  markup language      First Advantage  Wellington Management  Chase Reference Data Distribution  System Soft Technologies  TD Bank Canada  JPMorgan Chase  Tata Consultancy (TCS)  PayPal  Citibank  Free Doctor Helpline  Wells Fargo  Huawei Technologies        frequent

Try 1 Question(s) Test


 Q45. Difference Between this() and super() ?
Core Java
Admin
info@buggybread.com
Ans. 1.this is a reference to the current object in which this keyword is used whereas super is a reference used to access members specific to the parent Class.

2.this is primarily used for accessing member variables if local variables have same name, for constructor chaining and for passing itself to some method whereas super is primarily used to initialize base class members within derived class constructor.

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

   Like      Discuss     java   oops   class   objects   inheritence   constructor   this   super

Try 1 Question(s) Test


 Q46. What is a stream and what are the types of Streams and classes of the Streams?
Admin
info@buggybread.com
Ans. A Stream is an abstraction that either produces or consumes information. There are two types of Streams :

Byte Streams: Provide a convenient means for handling input and output of bytes.

Character Streams: Provide a convenient means for handling input & output of characters.

Byte Streams classes: Are defined by using two abstract classes, namely InputStream and OutputStream.

Character Streams classes: Are defined by using two abstract classes, namely Reader and Writer.

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

   Like      Discuss     java   file io   streams   byte stream   character stream


 Q47. What is Generalization and Specialization in terms of casting ?Core Java
Admin
info@buggybread.com
Ans. Generalization or UpCasting is a phenomenon where a sub class is prompted to a super class, and hence becomes more general. Generalization needs widening or up-casting. Specialization or DownCasting is a phenomenon where a super class is narrowed down to a sub class. Specialization needs narrowing or down-casting.

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

   Like      Discuss     java   data types   casting   up casting   downcasting   generalization   specialization     Tata Consultancy (TCS)  VirtusaPolaris


 Q48. What things should be kept in mind while creating your own exceptions in Java?Core Java
Admin
info@buggybread.com
Ans. All exceptions must be a child of Throwable.

If you want to write a checked exception that is automatically enforced by the Handle or Declare Rule, you need to extend the Exception class.

You want to write a runtime exception, you need to extend the RuntimeException class.

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

   Like      Discuss     java   exceptions   exception handling   user defined exceptions   throwable   architecture   library development   technical architect   technical lead


Frequently asked to fresh graduates and less experienced.
 Q49. Difference between Compositions and Inheritance ?Core Java
Admin
info@buggybread.com
Ans. Inheritance means a object inheriting reusable properties of the base class. Compositions means that an abject holds other objects.

In Inheritance there is only one object in memory ( derived object ) whereas in Composition , parent object holds references of all composed objects.

From Design perspective - Inheritance is "is a" relationship among objects whereas Composition is "has a" relationship among objects.

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

   Like      Discuss     java   oops   oops concepts   inheritance   composition   difference between   basic interview question      basic        frequent

Try 2 Question(s) Test



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



Frequently asked question in companies using hibernate.
  Q50. Difference between first level and second level cache in hibernate ?Hibernate
Admin
info@buggybread.com
Ans. 1. First level cache is enabled by default whereas Second level cache needs to be enabled explicitly.

2. First level Cache came with Hibernate 1.0 whereas Second level cache came with Hibernate 3.0.

3. First level Cache is Session specific whereas Second level cache is shared by sessions that is why First level cache is considered local and second level cache is considered global.

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

   Like      Discuss     hibernate   orm   hibernate cache   architecture   technical lead     EFI  Geometric  QuinStreet  Cognizant (CTS)  ZS Associates  Walt Disney      Intermediate        frequent


 Q51. How to configure second level cache in Hibernate ?Hibernate
Admin
info@buggybread.com
Ans. 1. Configure Provider class in Hibernate configuration file.

2. Add Cache usage tag ( read-only or read-write ) in mapping files ( hbm ).

3. Create an XML file called ehcache.xml and place in classpath which contains time settings and update settings, behavior of cache , lifetime and idletime of Pojos, how many objects are allowed.

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

   Like      Discuss     hibernate   orm   hibernate cache   architecture


 Q52. What are the contents of Hibernate configuration file ( hibernate.cfg.xml ) ?Hibernate
Admin
info@buggybread.com
Ans. HBM Files ( Mapping )DB Connection ( DB Connection String , User Name , Password , Pool Size )SQL Dialect ( SQL variant to be generated )Show SQL ( Show / No show SQL on Console )Auto Commit ( True / False )

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

   Like      Discuss     hibernate   configuration   barclays     Mphasis  Mccoy Global Links  Availity  Infosys  GlobalLogic


 Q53. Which annotations are used in Hibernate ?Hibernate
admin
info@buggybread.com
Ans. @Entity
@Table
@Id
@Column
@Temporal
@Basic
@Enumerated
@Access
@Embeddable
@Lob
@AttributeOverride
@Embedded
@GeneratedValue
@ElementCollection
@JoinTable
@JoinColumn
@CollectionId
@GenericGenerator
@OneToOne
@OneToMany
@ManyToOne
@ManyToMany
@NotFound

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

   Like      Discuss     hibernate   annotations


 Q54. Can we override compareTo method for Enumerations ?Core Java
Admin
info@buggybread.com
Ans. No. compareTo method is declared final for the Enumerations and hence cannot be overriden. This has been intentionally done so that one cannot temper with the sorting order on the Enumeration which is the order in which Enum constants are declared.

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

   Like      Discuss     java   compareto   final methods   enum   enumeration      expert


 Q55. 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     database   insert-update   db exceution plan   db strategy   design   architecture   technical lead


Very Frequently asked.
 Q56. Explain throw, throws , try and catch in Java ?Core Java
Admin
info@buggybread.com
Ans. throw is used to re throw an exception.

throws is used to declare that the method throws the respective exceptions.

try block is used to identify if the respective block has thrown any exception.

catch is used to catch the exception that has been thrown by the respective try block.

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

   Like      Discuss     java   exception handling   throw   throws   try   catch     Vidram Solutions  Cognizant (CTS)      basic        frequent


Frequently asked to fresh graduates and less experienced.
 Q57. Why do we write public static void main ? Can we use some other syntax too for main ?Core Java
Admin
info@buggybread.com
Ans.
1. public is the access modifier that makes the method accessible from anywhere, static is the keyword that makes it accessible even without creating any object and using class name only , void means it doesnt return anything , String args[] is the array of argument that this method receives.

2. If I use Main , it will compile correctly as Java will treat it as just another method but it wont be the method "main" which Java looks for when it looks to execute the class and hence will throw

Error: Main method not found in class , please define the main method as:
public static void main(String[] args)

3. Main is not a keyword but a special string that Java looks for while initiating the main thread.

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

   Like      Discuss     java   main method     Cognizant (CTS)  Computer Solutions & Software International (CSSI)  Telcoinabox      basic        frequent

Try 1 Question(s) Test


 Q58. What is a transitive dependency ? Can we override Transitive Dependency version and If Yes, how ?Maven
Admin
info@buggybread.com
Ans. Transitive dependency is the dependencies not defined directly in the current POM but the POM of the dependent projects.

Yes we can override transitive dependency version by specifying the dependency in the current POM.

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

   Like      Discuss     maven   maven dependencies   maven transitive dependency   technical lead   build management


Not frequently asked as it was introduced with Java 8.
 Q59. What is StringJoiner ?Core Java
Admin
info@buggybread.com
Ans. StringJoiner is a util method to construct a string with desired delimiter. This has been introduced with wef from Java 8.

Sample Code

StringJoiner strJoiner = new StringJoiner(".");
strJoiner.add("Buggy").add("Bread");
System.out.println(strJoiner); // prints Buggy.Bread


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

   Like      Discuss     java   java8   java 8   string   stringjoiner



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q60. Which of the following can be marked static ?

a. Methods , Variables and Initialization Blocks.
b. Methods , Variables , Initialization Blocks and Outer Classes and nested Classes.
c. Methods , Variables , Initialization Blocks and Outer Classes.
d. Methods , Variables , Initialization Blocks and nested Classes
Anonymous
Ans. Methods , Variables , Initialization Blocks and nested Classes

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

   Like      Discuss     oops   java   static   nested classes   static nested classes

Try 2 Question(s) Test


 Q61. Which of the following collections stores its elements in insertion Order ?

a. HashMap
b. TreeMap
c. LinkedHashMap
d. LinkedMap
Core Java
Anonymous
Ans. LinkedHashMap

  Sample Code for LinkedHashMap

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

   Like      Discuss     linkedhashmap   collections   java   map


 Q62. In what order the elements of a HashSet are retrieved ?

a. Random Order
b. Insertion Order
c. Natural Sorting Order
d. Inverse Natural Sorting Order
Core Java
Anonymous
Ans. Random Order

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

   Like      Discuss     collections   set   hashset   java

Try 1 Question(s) Test


 Q63. Which of the following file is called deployment descriptor ?

a. application.xml
b. project.xml
c. web.xml
d. build.xml
Anonymous
Ans. web.xml

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

   Like      Discuss     configuration files   deployment   server   java


 Q64. Collections.sort can only be performed on ..

a. Set
b. List
c. Map
d. Any Collection implementation
Anonymous
Ans. List

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

   Like      Discuss     collections   java   sorting

Try 2 Question(s) Test


 Q65. Which of the following is dependency exclusion ?

a. A doesn't depend on C and then A marks C as excluded.
b. A Depends on B and B depends on C and then A can mark B as excluded.
c. A and B depends on C and then they can mark C as excluded.
d. A depends upon B and B depends upon C then A marks C as excluded.
Maven
Anonymous
Ans. A depends upon B and B depends upon C then A marks C as excluded.

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

   Like      Discuss     maven   dependency exclusion


 Q66. Which of the following is false about main method ?

a. It should be declared public and static
b. it should have only 1 argument of type String array
c. We can override main method
d. We can overload main method
Anonymous
Ans. We can override main method

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

   Like      Discuss     java   main method


 Q67. Which of the following is false about Constructors ?

a. Constructor can be overloaded
b. A no argument constructor is provided by the compiler if we declare only constructors with arguments.
c. Constructors shouldn't have any return types , not even void.
d. If super is not explicitly called, still super() is intrinsically added by the compiler.
Core Java
Anonymous
Ans. A no argument constructor is provided by the compiler if we declare only constructors with arguments.

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

   Like      Discuss     java   oops   constructor

Try 2 Question(s) Test


 Q68. Which of the following doesn't extend Collection interface ?

a. Set
b. List
c. Map
d. Queue
Core Java
Anonymous
Ans. Map

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

   Like      Discuss     java   collections   collection interface


 Q69. Which of the following Java feature promotes Code Re usability ?

a. Abstraction
b. Encapsulation
c. Inheritance
d. Polymorphism
Core Java
Anonymous
Ans. Inheritance

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

   Like      Discuss     java   java concepts   java features   code reusability



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q70. Which of the following Java feature promotes access protection or Hiding ?

a. Inheritance
b. Encapsulation
c. Abstraction
d. Composition
Anonymous
Ans. Encapsulation

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

   Like      Discuss     java   java concepts   java features   oops concepts   oops features   access protection   information hiding


 Q71. Which of the following is not a build tool ?

a. Maven
b. Ant
c. Gradle
d. svn
Tool
Anonymous
Ans. svn

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

   Like      Discuss     java   build tools


 Q72. enums are intrinsically ..

a. private
b. public
c. static
d. final
Core Java
Anonymous
Ans. static

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

   Like      Discuss     java   enum


 Q73. Enums cannot be declared ..

a. private
b. public
c. static
d. final
Core Java
Anonymous
Ans. final

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

   Like      Discuss     java   enum


 Q74. Difference between parameters and arguments ?
Admin
info@buggybread.com
Ans. Parameters are the variables that the method is expected to receive along with the method call. Arguments are the values which are passed on while calling the methods.

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

   Like      Discuss     parameter   argument  method   function  java      basic


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


 Q76. Why Java is not considered pure OOP's language ?Core Java

Ans. There are 2 reasons for it.

1. Usage of Primitive types - Though Java provides classes for the primitive data types but as the usage of primitives is permissible, its considered unpure OOP's language.

2. Usage of Static members - Static members belong to the class and not objects and hence not considered fit for pure OOP's programming.

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

   Like      Discuss     oops  object oriented programming  object oriented language  primitive data types     BSL Information Technology  Data64


This question can be asked in different variants like performace improvement of an application, improving performance for DB communication etc.
 Q77. What are the ways in which execution time of the code can be improved ?Solution2016-05-29 09:42:39

Ans. This depends on entirely upon the code type. For example

1.If its just logic, we can try it to short circuit or put the if / switch case with maximum probability in the beginning.

2. Can use faster data structures, for eg - random retrieval instead of sequence / iterator

3. Working with primitive types or even bytes instead of Objects, even though it may result in marginal improvement.

4. If its service call, then service call with bulk load can help

5. If DB Operation, then with use of Indices , Views or using ORM , cache etc.


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

   Like      Discuss     performance improvement  code optimization     Visa Inc


 Q78. What are constructors and Destructors in Java ?Core Java2016-06-03 10:09:28

Ans. Constructors are used for initializing the object state once it is initialized and memory has been reserved for it.

Destructor is used to de-allocate memory allocated by objects.

There are no destructors in Java. Alternatively, Java provides Automatic garbage collection i.e automatically releasing the un-referenced memory.


  Sample Code for constructor

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

   Like      Discuss     constructors  destructors     Quinnox  Tribro

Try 1 Question(s) Test


Frequently asked. Among first few questions in the J2EE segment of interview.
  Q79. What is the use of deployment descriptor ?Java EE2016-06-04 22:46:40

Ans. Deployment Descriptor which is usually web.xml is used to specify the classes, resources and configuration of the application and how the web server uses them to serve web requests.This file is usually added to WEB-INF folder and contains following

* Servlet entries and url mapping
* Plugins
* Some info regarding authentication / filters
* Landing Page
* Event Handlers

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

   Like      Discuss     web.xml   servlets  deployment descriptor     The NewBury Corp  Fast Dolphin  uCertify  General Electric  Cognizant (CTS)  Web coop  HCL Technologies  Tara Consultancy (TCS)  Wipro  Infosys  Cognizant (CTS)  Sonatype  IBM      basic        frequent

Try 1 Question(s) Test



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q80. Why HashTable has been deprecated ?2016-07-08 10:01:58

Ans. HashTable has been Deprecated as an alternative HashMap has been provided. The only difference between the HashTable and HashMap is that Hashtable is synchronized whereas HashMap is not. Most of the synchronized collections have been deprecated and their raw alternative has been given.

Synchronization has a cost. Using synchronized collection at a place where there is hardly any need of it would means useless utilization of resources. As these collections are rarely used in static context or shared among threads, Java might have thought it better to just provide the raw collection and let developer implement synchronization if he feels the need to do so.

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

   Like      Discuss     hashtable  synchronized collections  Why synchronized collections have been deprecated  Why HashTable has been deprecated  HashTable vs HashMap

Try 3 Question(s) Test


Basic and Very Frequently asked.
  Q81. What is Polymorphism in Java ?Core Java2016-11-06 09:10:54

Ans. Polymorphism means the condition of occurring in several different forms.

Polymorphism in Java is achieved in two manners

1. Static polymorphism is the polymorphic resolution identified at compile time and is achieved through function overloading whereas

2. Dynamic polymorphism is the polymorphic resolution identified at runtime and is achieved through method overriding.

  Sample Code for overloading

  Sample Code for overriding

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

   Like      Discuss     polymorphism  oops concepts     Credit Suisse  Unbounded Solutions  Microsoft   Google  Purch  HCL Technologies  Tata Consultancy (TCS)  Wipro  Mathworks  Accenture  ZonOff  ZapCom  Addteq  Priceline.com      Basic        frequent

Try 2 Question(s) Test


Very frequently asked in HCL Tech ( Based of 4 inputs )
  Q82. Write a Program to reverse a string iteratively and recursivelyCore Java

Ans. Using String method -

new StringBuffer(str).reverse().toString();

Iterative -

public static String getReverseString(String str){
StringBuffer strBuffer = new StringBuffer(str.length);
for(int counter=str.length -1 ; counter>=0;counter--){
strBuffer.append(str.charAt(counter));
}
return strBuffer;
}

Recursive -

public static String getReverseString(String str){
if(str.length <= 1){
return str;
}
return (getReverseString(str.subString(1)) + str.charAt(0);
}

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

   Like      Discuss     string  StringBuffer  recursion  for loop  stringbuffer.append  java.lang.String  java.lang.StringBuffer     HCL Technologies  Ocado  BlackRock  Oracle  FINRA  Arezzo Sky  Zalando  Boeing        frequent


  Q83. What are the different types of inner classes ?Core Java
Anonymous
Ans. Simple Inner Class,
Local Inner Class,
Anonymous Inner Class,
Static Nested Inner Class.

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

   Like      Discuss     java   inner classes   classes     Infosys  Tata Consultancy (TCS)  HCL Technologies  IBM  IBM India  Gateway Media      basic        frequent

Try 1 Question(s) Test


 Q84. 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     java   java5   data types   wrapper classes   adapter design pattern        rare


 Q85. Does Constructor creates the object ?Core Java
Anonymous
Ans. New operator in Java creates objects. Constructor is the later step in object creation. Constructor's job is to initialize the members after the object has reserved memory for itself.

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

   Like      Discuss     java   constructor   object creation      intermediate        rare


  Q86. Does Java support Multiple Inheritance ?Core Java
Anonymous
Ans. Interfaces does't facilitate inheritance and hence implementation of multiple interfaces doesn't make multiple inheritance. Java doesn't support multiple inheritance.

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

   Like      Discuss     java   oop   oop concepts   inheritence   multiple inheritence   basic interview question     Credit Suisse  Sun Microsystems  VMware  NSEiT  Exterro  theScore  JP Morgan      basic        frequent

Try 1 Question(s) Test


Very frequently asked. Favorite question in Walk in Drive of many Indian service companies.
  Q87. What is a Final Variable ?Core Java
Anonymous
Ans. Final variable is a variable constant that cannot be changed after initialization.

  Sample Code for final variable

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

   Like      Discuss     oops   java   final   final variable   basic interview question     IBM  Goldman Sachs  TrueCar  Intertek  RedMane  Antra  HCL Technologies  Tata Consultancy (TCS)  Accenture  Forte Group  Mastercard      basic        frequent

Try 1 Question(s) Test


 Q88. Which String class does not override the equals() and hashCode() methods, inheriting them directly from class Object?Core Java
Anonymous
Ans. java.lang.StringBuffer.

  Sample Code for StringBuffer

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

   Like      Discuss     java   object class   stringbuffer      expert        rare


Very frequently asked. Favorite question in Walk in Drive of many Indian service companies.
  Q89. What is a final method ?Core Java
Anonymous
Ans. Its a method which cannot be overridden. Compiler throws an error if we try to override a method which has been declared final in the parent class.

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

   Like      Discuss     java   oops   final   final method     Oracle  Intertek  HCL Technologies  Tata Consultancy (TCS)  Accenture   IBM  Goldman Sachs   TrueCar   Intertek RedMane   Antra      basic        frequent

Try 1 Question(s) Test



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



Very frequently asked across all types of companies.
  Q90. Difference between HashMap and Hashtable?Core Java
Anonymous
Ans. Hashtable is synchronized whereas HashMap is not.HashMap allows null values whereas Hashtable doesnt allow null values.

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

   Like      Discuss     java   collections   hashmap   map   hashtable   basic interview question   ebay   tcs    hcl technologies   infosys technologies     Morgan Stanley  Yahoo  Q3 Technologies  PriceLine  Solution Rally  Coupang  HCL Technologies  Tata Consultancy (TCS)   Infosys Technologies  Accenture India  JPMorgan Chase  Priceline.com      basic        frequent

Try 2 Question(s) Test


 Q91. When are static variables loaded in memory ?Core Java
Anonymous
Ans. They are loaded at runtime when the respective Class is loaded.

  Sample Code for static variable

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

   Like      Discuss     java   oops   static   static variable   memory      intermediate


 Q92. Can we serialize static variables ?Core Java
Anonymous
Ans. No. Only Object and its members are serialized. Static variables are shared variables and doesn't correspond to a specific object.

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

   Like      Discuss     serialization   java   oops   static   static variables     Deloitte      intermediate        rare

Try 2 Question(s) Test


 Q93. There are two objects a and b with same hashcode. I am inserting these two objects inside a hashmap.

hMap.put(a,a);
hMap.put(b,b);

where a.hashCode()==b.hashCode()

Now tell me how many objects will be there inside the hashmap?
Core Java
Anonymous
Ans. There can be two different elements with the same hashcode. When two elements have the same hashcode then Java uses the equals to further differentation. So there can be one or two objects depending on the content of the objects.

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

   Like      Discuss     java   hashcode   map   hashmap   object reference   advanced


 Q94. Can constructors be synchronized in Java ?Core Java
Anonymous
Ans. No. Java doesn't allow multi thread access to object constructors so synchronization is not even needed.

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

   Like      Discuss     synchronization   synchronize   constructor   java   multithreading   yes-no   advanced     Tieto      expert        rare


 Q95. Can we use null as a key for a map collection ?Core Java
Anonymous
Ans. Yes , for HashMap. HashMap implements Map interface. HashMap allows one null key and any number of null values.

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

   Like      Discuss     java   collections   hashmap   map   hashtable   yes-no     BlackBerry


 Q96. What are wrapper classes ?Core Java
Anonymous
Ans. They are wrappers to primitive data types. They allow us to access primitives as objects.

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

   Like      Discuss     java   data types   wrapper classes     CSL  Xoriant  Webilent      basic        frequent


Usually asked only to fresh graduates.
 Q97. What is the difference between time slicing and preemptive scheduling ?Operating System
Anonymous
Ans. In preemptive scheduling, highest priority task continues execution till it enters a not running state or a higher priority task comes into existence. In time slicing, the task continues its execution for a predefined period of time and reenters the pool of ready tasks.

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

   Like      Discuss     operating system   scheduling   threads   multi threading        rare


 Q98. What one should take care of, while serializing the object?
Anonymous
Ans. One should make sure that all the included objects are also serializable. If any of the objects is not serializable then it throws a NotSerializable Exception.

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

   Like      Discuss     serialization   java   oops   object      expert


  Q99. What is a String Pool ?Core Java
Anonymous
Ans. String pool (String intern pool) is a special storage area in Java heap. When a string is created and if the string already exists in the pool, the reference of the existing string will be returned, instead of creating a new object and returning its reference.

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

   Like      Discuss     java   oops   string   string class   string pool   heap memory     SAS Institute  Ariba  GuideWire  Harbinger  Oracle  Virtusa  Knoa  Polaris  GuideWire  HCL Technologies  Tata Consultancy (TCS)  Infosys  Technologent  MphasiS  Harbinger Group  Kony  Evergent  NTT Data  VMware  Markit  Ariba  Tech Mahindra  Bureau Veritas  InfoStretch  PTC Software      intermediate        frequent

Try 2 Question(s) Test



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q100. What is casting?Core Java
Anonymous
Ans. There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference

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

   Like      Discuss     java   data types   casting   basic interview question     Mindtree  HCL Technologies  Wipro  Tata Consultancy (TCS)  Infosys      basic        frequent


next 100


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:
         

Message Feed    X Close this

Bank Of America: (Diamond problem for a variable) interface A ... Anonymous

ADP: Following questions were asked how can execute ... Anonymous

Wipro: was asked questions for core java and ... Anonymous

Computer sciences corporation (csc): There were standard java uqestions .need some ... Anonymous

STRUTS: I was so good with this framework ... Anonymous

Windows: This is probably the worst platform for ... Naveen