Java Interview Questions and Answers
Java Interview Questions and Answers
Java Interview Questions and Answers
Questions Tests Java Class List Big Data Best Of Java Discussion Search Subscribe
Submit Question
Very Very frequently asked. Among the first few questions in almost all interviews.Among Top 5 frequently asked questions. Frequently asked in
Indian service companies (HCL,TCS,Infosys etc, Based on multiple feedback )
Ans. "equals" is the method of object class which is supposed to be overridden to check object equality, whereas "==" operator
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.
Sample code:
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 1/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve 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 IQOR Science Vanguard eClinicalWorks Experticity Blue Cross and Blue Shield of
Kansas ComTrade Banja Luka Overstock.com Intrasoft International IBM Apex Systems infoview technologies basic frequent
Advanced level question. Frequently asked in High end product companies. Frequently asked in Cognizant ( Based on 2 feedbacks )
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 -
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 2/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
// 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 Correct / Improve 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 Bytecode Cyber Security Calsoft Systems IDS Infotech expert
frequent
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 Core Java Anonymous
StringBuffer ?
or
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 3/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
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).
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java string class string stringbuilder stringbuffer Cognizant (CTS) San Jose State
University (SJSU) HCL Technologies Deloitte Sophos Hitachi JPMorgan Chase IBM Kony Labs Keystone ebay TIAA Financial Services Ancestry
basic frequent
Frequently asked to fresh graduates and less experienced developers. Among the first few questions in many interviews.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 4/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
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.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve 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
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 5/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
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 Correct / Improve java memory memory management stack memory heap memory code segment memory
advanced NX Developer Velocity Commvault eBizprise Taiwan Tata Consultancy (TCS) expert frequent
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
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 6/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
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.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java inner classes classes objects technical lead intermediate
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java oops object creation new operator class.forname cloning ebay
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 7/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Intelligrape Infosys Polaris British Telecom (BT) Vyom Labs Deutsche Bank HCL Technologies expert
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.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java overriding access specifier inheritence oops polymorphism runtime polymorphism
Genpact
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 8/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.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 Correct / Improve java string class string jvm memory management string pool GuideWire NTT
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 9/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
OpenXava
Check everything
SPRING MVC Apache Stripes that is Best in Java
Click Here
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 Correct / Improve java statically typed language variable declaration basic frequent
Ans. Declaration is intimation to the compiler about the nature of Data a reference is going to hold.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 10/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
For example
For example
** 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 Correct / Improve declaration instantiation initialization construction basic frequent
Ans. "this" keyword is a reference to the current object and can be used for following -
2. Referring to the instance variable when local variable has the same name.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 11/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java this object reference constructor chaining intermediate rare
Q13. Does garbage collection guarantee that a program will not run out of Core Java Anonymous
memory?
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 Correct / Improve java garbage collection java memory management advanced
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 12/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Json Anonymous
Q14. What are the benefits of JSON over XML ?
Object Representation - Information is presented in object notations and hence better understandable.
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 Correct / Improve json markup language QualiTest intermediate frequent
Frequently asked.
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.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 13/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java collections list arraylist linkedlist difference between architecture data structure
Hibernate Admin
Q16. What is Lazy Initialization in Hibernate ? 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 Correct / Improve 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 HCL Technologies
Basic frequent
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 14/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Lambda Expression are useful to write shorthand Code and hence saves the effort of writing lengthy Code.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java java8 lambda expression architecture Axxess CACI ZonOff Dell India Wellington
Q18. Which of the following combination of keywords is illegal in Java ? Core Java Anonymous
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 15/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java java keywords VirtusaPolaris IVTL InfoView Technologies basic
Core Java
Q19. What are different types of classes ?
Ans. There are different verticals in which Java Classes can be classified.
Help us improve. Please let us know the company, where you were asked this question :
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 16/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
OpenXava
Check everything
SPRING MVC Apache Stripes that is Best in Java
Click Here
Ans. By putting code within static method. With Java 6 and earlier versions, even static block can be used.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java oops static static method static block American Express Cognizant (CTS)
basic frequent
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 17/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
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 Correct / Improve java oops oops concepts encapsulation abstraction basic interview question
Synechron Amazon HCL Technologies Tata Consultancy (TCS) Wipro Infosys Technologies 3DPLM Software Solutions basic frequent
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 Correct / Improve java oops this super constructor intermediate rare
Very frequently asked. Favorite question in Walk in Drive of many Indian service companies. Frequently asked in HCL Technologies.
Ans. final - constant variable, objects cannot be de-referenced, restricting method overriding, 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.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 19/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve 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
Hibernate Admin
Q24. What are the ways to avoid LazyInitializationException ? info@buggybread.com
3. Make sure that we are accessing the dependent objects before closing the session.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 20/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve hibernate lazy loading hibernate lazy initialization hibernate lazyinitializationexception
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 Correct / Improve java oops constructor super inheritance inheritence Itech intermediate
Q26. 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 Correct / Improve java memory management object creation advanced ebay
Spring Admin
Q27. Explain Flow of Spring MVC ? info@buggybread.com
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 View is rendered and the Dispatcher Servlet sends the output to the Servlet container.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 22/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve j2ee spring mvc frameworks web applications architecture Accenture fidelity IBM
Java EE Admin
Q28. What is session tracking and how do you track a user session in
servlets? 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 :
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 23/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Like Discuss Correct / Improve j2ee servlets session session management web applications cookies httpsession url
Advanced level question frequently asked in US based companies. Recently asked in EMC and Intuit.
Solution Admin
Q29. Can you provide some implementation of a Dictionary having large
number of words ? 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.
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)
}
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java collections hashmap binary search search algorithm advanced architecture data
structure Dell EMC Intuit Corporate Brokers PWC India Yahoo Oracle frequent
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 24/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
OpenXava
Check everything
SPRING MVC Apache Stripes that is Best in Java
Click Here
Very frequently asked. Favorite question in Walk in Drive of many Indian service companies.
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.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java collections map treemap hashmap Amber Road CTS (Cognizant) ION
Trading DataMetica Accenture The Advisory Board Company BidGely Infosys Tata Consultancy (TCS) HCL
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 25/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
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 UST Global basic frequent
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 Correct / Improve 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
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve string string class java == object references coding basic frequent
Advanced level question usually asked in High end product companies. Have been asked in Google and Amazon (Based on 1 Feedback)
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.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 27/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java garbage collection java memory management advanced
LinkedIn Infosys Google Netflix Amazon Huawei Technologies JP Morgan enGenius CitiusTech Goldman Sachs Bank Of America
Frequently asked. Favorite question in Walk in Drive of many Indian service companies.
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.
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 :
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 28/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Like Discuss Correct / Improve 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
Xml Admin
Q35. Difference between SAX and DOM Parser ? 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 Correct / Improve 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
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 29/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Canada JPMorgan Chase Tata Consultancy (TCS) PayPal Citibank Free Doctor Helpline Wells Fargo Huawei Technologies frequent
Ans. String is immutable in java and stored in String pool. Once it's created it stays in the pool until unless garbage collected, so
even though we are done with password it's available in memory for longer duration and there is no way to avoid it. It's a security
risk because anyone having access to memory dump can find the password as clear text.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java string class string immutable string pool garbage collection advanced General
Database Admin
Q37. What is database deadlock ? How can we avoid them? 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
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 30/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
unresponsive.
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.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve 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.
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.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 31/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
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.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve 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
Ans. Final variable means a variable that has been declared final and hence cannot be de referenced after initialization. Effective
final means a variable that has not been declared final but haven't been reassigned the value after initialization.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 32/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
First is the regulation that restricts the reassignment and will raise a compilation error if we try to do so. Second is the outcome
without the restriction.
Effective Final is the eventual treatment of the variable that is required for many features. For eq - Java 8 requires that local
variables referenced from a lambda expression must be final or effectively final.It means all local referenced from lambda
expressions must be such that their value shouldn't be changed after initialization whether declared final or not.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java java8 java 8 final effective final final vs effective final lambda expressions
expert
OpenXava
Check everything
SPRING MVC Apache Stripes that is Best in Java
Click Here
Q40. Why do we write public static void main ? Can we use some other Core Java Admin
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 33/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.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 Correct / Improve java main method Cognizant (CTS) Computer Solutions & Software International
Ans. Advantages
Can do meta object operations ( like validating something before creating objects , keep count of number of objects )
Can do operations which have nothing to do with objects but still you want them to be tied to Class.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 34/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Disadvantages
Commonly used to static variables sometime leads to problems due to access by different objects.
Are not tied to objects so doesn't reflect pure Object Oriented approach.
Some limitation in testing as not all frameworks have facility to mock them. Powermock has but Mockito doesnt
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java static static variables static methods
Q42. Which keyword is used to provide explicit access of a code block to Core Java Anonymous
single thread ?
a. Transient
b. Final
c. Explicit
d. Synchronized
Ans. Synchronized
Help us improve. Please let us know the company, where you were asked this question :
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 35/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Like Discuss Correct / Improve java threads multithreading Infoview HCL Technologies basic
a. private
b. public
c. static
d. final
Ans. final
Help us improve. Please let us know the company, where you were asked this question :
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 )
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 36/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve 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 3DPLM Software Solutions
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java java5 generics enum autoboxing annotations static import rare
Anonymous
Q46. What one should take care of, while serializing the object?
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.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 37/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
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 Correct / Improve 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 Mindtree Centre for Internet and Society (CIS) Trimax IT Infrastructure & Services intermediate frequent
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 38/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Very frequently asked. Usually asked in different variants like Diff between StringBuffer , String Builder ; Difference between StringBuilder and String
class; Choice between these classes etc.
Ans. A string buffer implements a mutable sequence of characters. A string buffer is like a String, but can be modified. At any point
in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through
certain method calls.
The String class represents character strings. All string literals in Java programs, such as "abc" are constant and implemented as
instances of this class; their values cannot be changed after they are created.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java string stringbuffer frequently asked BlackRock Synechron RedMane
Technology Velopsys Technologies American Express Sophos QualiTest ebay Infosys Technologies basic frequent
Q49. What is JDBC? Describe the steps needed to execute a SQL query using Database Anonymous
JDBC.
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.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 39/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
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 Correct / Improve java jdbc db connectivity Nucleus Software Exports Caprus IT basic
frequent
OpenXava
Check everything
SPRING MVC Apache Stripes that is Best in Java
Click Here
Q50. Are constructors inherited? Can a subclass call the parent's class Core Java Anonymous
constructor? When?
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 :
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 40/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Like Discuss Correct / Improve java oops constructor inheritence expert rare
Very Frequently asked to fresh graduates and less experienced. Favorite question in Walk in drives.
Ans. Overloading - Similar Signature but different definition , like function overloading.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java oops overloading overriding oops concepts basic interview question PC
Technology Cognizant (CTS) Donlen hybris Software RedMane Allerin Technologies Gemalto Allerin Technologies HCL Technologies Tata Consultancy
(TCS) Accenture India Infosys Technologies Polaris United Healthcare India IBM India Xchanging American Express Antra Flipp Computer Sciences
Corporation (CSC) Garmin NetSuite Donlen Hudsons Bay Techlogix SevOne Synactive Oodles Technologies FDM Group Marlabs RedMane
Technology Faichi Solutions TD Tech Mahindra Shutterfly Luxoft PC Technology CCC Information Services State Farm Raja
Software Mastek EPAM Morgan Stanley SummitWorks Sony Citibank Emtec LowerMyBills Consilience Xavor AllState FasTrak AmTrust Financial Walt
Disney Ultramain Systems International Turnkey Systems Knoldus Software CA Technologies Amdocs FDM Group Hybris Fidelity United Health Group
(UHG) Bluewhale Solutions Pegasystems Revature Innoplexus Vanguard AptSource Perficient Grapecity Subex QuintilesIMS NimbleUser Expeditors
Associate Sapient HR Cloud Summitworks Jabong.com Kony Labs Price Waterhouse Coopers (PWC) basic frequent
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 41/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java basic interview question vector arraylist collections synchronization
Oracle Lab49 Infosys Wipro Zoho HCL Technologies Tata Consultancy (CTS) BirlaSoft Emory Xplana British Telecom (BT) Apex
Systems Capgemini Accenture 3dplm Software Solution AppKnox eIntern Landmark Information Group ESystems Orbitz
Worldwide HARMAN Starmount iConsultus KARYA Technologies Smart Chip Cuelogic Technologies Kronos Trigent Software Deloitte ACI
Ans. Though It's often confused with each other, Object Creation ( Instantiation ) and Initialization ( Construction ) are different
things in Java. Construction follows object creation.
Object Creation is the process to create the object in memory and returning its handler. Java provides New keyword for object
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 42/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
creation.
Initialization is the process of setting the initial / default values to the members. Constructor is used for this purpose. If we don't
provide any constructor, Java provides one default implementation to set the default values according to the member data types.
Help us improve. Please let us know the company, where you were asked this question :
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 Correct / Improve java oops static static methods java keywords Oracle
Q55. What are Marker Interfaces ? Name few Java marker interfaces ? Core Java Anonymous
Ans. These are the interfaces which have no declared methods.Serializable and cloneable are marker interfaces.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java oops interfaces marker interface serializable clonable Qualtech
Consultants Computer Sciences Corporation (CSC) Addteq Infosys Synechron Amdocs JPMorgan Chase Qualtech Consultants Velopsys
Technologies Amdocs Ericsson Oracle Avaya Copart Innoplexus Volvo Information Technology intermediate frequent
Spring Admin
Q56. What are the benefits of using Spring Framework ? 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.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 44/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
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 Correct / Improve java spring framework mvc spring container architecture technical architect java
Advanced level question. Recently asked in few Indian service companies ( Based on 3 inputs )
Extensions - Loads jar files from JDK extensions directory - usually lib/ext directory of the JRE
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java jvm memory management class loaders bootstrap extensions system classloaders
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 45/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
advanced technical lead technical architect Deloitte Mindtree Accenture Synechron IBM
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 Correct / Improve java oops class objects inheritence constructor this super
Ans. Arrays are of fixed size and have to reserve memory prior to use. Hence if we don't know size in advance arrays are not
recommended to use.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 46/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Arrays store its values in contentious memory location. Not suitable if the content is too large and needs to be distributed in
memory.
There is no underlying data structure for arrays and no ready made method support for arrays, for every requriment we need to
code explicitly
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java arrays disadvantages of arrays arrays memory arrays vs variables
OpenXava
Check everything
SPRING MVC Apache Stripes that is Best in Java
Click Here
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.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 47/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
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 Correct / Improve java file io streams byte stream character stream
Ans. Collections can only hold objects, It can't hold primitive data types.
Collections have performance overheads as they deal with objects and offer dynamic memory expansion. This dynamic expansion
could be a bigger overhead if the collection class needs consecutive memory location like Vectors.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java collections collections classes disadvantages of collections over arrays collections vs
arrays
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 48/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.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 Correct / Improve java data types casting up casting downcasting generalization specialization Tata
Consultancy (TCS) VirtusaPolaris
Advanced level question usually asked to senior developers , leads and architects.
Ans. Volatile is an instruction that the variables can be accessed by multiple threads and hence shouldn't be cached. As volatile
variables are never cached and hence their retrieval cannot be optimized.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java java keywords volatile synchronization compiler optimization variable caching
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 49/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Ans. 1)The overriding methods can throw any runtime Exception , here in the case of runtime exception overriding method
(subclass method) should not worry about exception being thrown by superclass method.
2)If superclass method does not throw any exception then while overriding, the subclass method can not throw any new checked
exception but it can throw any runtime exception
3) Different exceptions in java follow some hierarchy tree(inheritance). In this case , if superclass method throws any checked
exception , then while overriding the method in subclass we can not throw any new checked exception or any checked exception
which are higher in hierarchy than the exception thrown in superclass method
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java overriding exceptions inheritence inheritance oops
Ans. Both belong to the class as a whole and not to the individual objects. Static methods are explicitly called for execution whereas
Static block gets executed when the Class gets loaded by the JVM.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 50/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java oops static static method static block difference between similarity basic
frequent
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 Correct / Improve java exceptions exception handling user defined exceptions throwable architecture library
development technical architect technical lead
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 51/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.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 Correct / Improve java oops oops concepts inheritance composition difference between basic interview
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 52/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Ans. 1. Static class is a class which cannot be instantiated and all its members are static whereas Singleton is the class that only
permit creation of single object and then the object is reused.
3. As Static class doesnt allow creating objects and hence it cannot be serialized.
4. Static class body is initialized eagerly at application load time whereas Singleton object can be initiated eagerly using static
blocks or lazily on first need.
5. Its not recommended to use pure static class as it fails to use many OOPs concepts.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve Static Class Singleton Static Class vs Singleton Netflix EPAM Ebay
Intermediate frequent
Hibernate Admin
Q69. Difference between first level and second level cache in hibernate ? 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.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 53/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve hibernate orm hibernate cache architecture technical lead
EFI Geometric QuinStreet Cognizant (CTS) ZS Associates Walt Disney Intermediate frequent
OpenXava
Check everything
SPRING MVC Apache Stripes that is Best in Java
Click Here
Hibernate Admin
Q70. How to configure second level cache in Hibernate ? info@buggybread.com
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 :
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 54/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Hibernate Admin
Q71. What are the contents of Hibernate configuration file (
hibernate.cfg.xml ) ? info@buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve hibernate configuration barclays Mphasis Mccoy Global
Links Availity Infosys GlobalLogic Cognizant (CTS) Overstock.com Erricson Erricson India HCL Technologies Tata Consultancy (TCS)
Hibernate admin
Q72. Which annotations are used in Hibernate ? info@buggybread.com
Ans. @Entity
@Table
@Id
@Column
@Temporal
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 55/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
@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 :
Ans. Predicate represents an anonymous function that accepts one argument and produces a result.
Supplier represents an anonymous function that accepts no argument and produces a result.
Consumer represents an anonymous function that accepts an argument and produces no result.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 56/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java java8 predicate consumer supplier lambda expression expert
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 Correct / Improve java compareto final methods enum enumeration expert
Q75. If you are given a choice to implement the code to either Insert a Solution admin
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 57/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Record or Update if already exist, Which approach will you follow ? info@buggybread.com
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.
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.
The benefit of saving 1st call in approach 1 should be bigger than the Book keeping for the exception.
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
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 58/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
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 Correct / Improve java exception handling throw throws try catch Vidram Solutions Cognizant (CTS)
basic frequent
Maven Admin
Q77. What is a transitive dependency ? Can we override Transitive
Dependency version and If Yes, how ? 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 Correct / Improve maven maven dependencies maven transitive dependency technical lead build management
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 59/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Maven Admin
Q78. What is a cyclic dependency ? info@buggybread.com
Ans. A has dependency of B, B has dependency of C and C has dependency of A,architecture,technical lead
With Maven 2 , came transitive dependency wherein in above scenario, C will acts as a dependency of A as if this dependency has
been defined directly in A but the negative side is that if it leads to cyclic dependency , it creates problems.
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve maven dependencies cyclic dependencies transitive dependencies build management
Synechron frequent
Ans. StringJoiner is a util method to construct a string with desired delimiter. This has been introduced with wef from Java 8.
Sample Code
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 60/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
OpenXava
Check everything
SPRING MVC Apache Stripes that is Best in Java
Click Here
Very Frequently asked. Have been asked in HCL Technologies very frequently ( based on 2 feedback ). Among first few questions in many interviews.
Ans. Abstract classes can have both abstract methods ( method declarations ) as well as concrete methods ( inherited to the
derived classes ) whereas Interfaces can only have abstract methods ( method declarations ).
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java classes abstract class interfaces GlobalLogic HCL Technologies Tata Consultancy
(TCS) Infosys Wipro Mindtree CapitalOne Accenture IBM India Infoview Technologies Salesforce AT&T United Health Group
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 61/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
(UHG) Verilogue Amazon Expeditors Syntel SalesForce Cornerstone OnDemand Expedia OLA NSF International Copper Mobile Think Future
Technologies MorphoTrust Global Healthcare Prodigious Internet Brands SciQuest arvato Systems iCIMS Ideas2IT virtusa polaris Vitech
Q81. Which of the following can be marked static ? Core Java Anonymous
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve oops java static nested classes static nested classes
Q82. Which of the following collections stores its elements in insertion Core Java Anonymous
Order ?
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 62/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
a. HashMap
b. TreeMap
c. LinkedHashMap
d. LinkedMap
Ans. LinkedHashMap
Help us improve. Please let us know the company, where you were asked this question :
Q83. In what order the elements of a HashSet are retrieved ? Core Java Anonymous
a. Random Order
b. Insertion Order
c. Natural Sorting Order
d. Inverse Natural Sorting Order
Ans. Random Order
Help us improve. Please let us know the company, where you were asked this question :
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 63/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Q84. Which of the following file is called deployment descriptor ? Java EE Anonymous
a. application.xml
b. project.xml
c. web.xml
d. build.xml
Ans. web.xml
Help us improve. Please let us know the company, where you were asked this question :
a. Set
b. List
c. Map
d. Any Collection implementation
Ans. List
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 64/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Help us improve. Please let us know the company, where you were asked this question :
Q87. Which of the following is false about main method ? Core Java Anonymous
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 65/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Q88. Which of the following is false about Constructors ? Core Java Anonymous
Help us improve. Please let us know the company, where you were asked this question :
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 66/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Q89. Which of the following doesn't extend Collection interface ? Core Java Anonymous
a. Set
b. List
c. Map
d. Queue
Ans. Map
Help us improve. Please let us know the company, where you were asked this question :
OpenXava
Check everything
SPRING MVC Apache Stripes that is Best in Java
Click Here
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 67/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Q90. Which of the following Java feature promotes Code Re usability ? Core Java Anonymous
a. Abstraction
b. Encapsulation
c. Inheritance
d. Polymorphism
Ans. Inheritance
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java java concepts java features code reusability
Q91. Which of the following Java feature promotes access protection or Core Java Anonymous
Hiding ?
a. Inheritance
b. Encapsulation
c. Abstraction
d. Composition
Ans. Encapsulation
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve java java concepts java features oops concepts oops features access protection
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 68/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
information hiding
a. Maven
b. Ant
c. Gradle
d. svn
Ans. svn
Help us improve. Please let us know the company, where you were asked this question :
a. private
b. public
c. static
d. final
Ans. static
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 69/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
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 Correct / Improve parameter argument method function java basic
Almost sure to be asked in every company using any Dependency Injection framework ( Spring, Guice etc )
Design
Q95. What is Dependency Injection or IOC ( Inversion of Control ) ?
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.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 70/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
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
Core Java
Q96. In which cases , moving methods to utility class could be useful ?
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 )
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 :
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 71/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Like Discuss Correct / Improve utility classes util classes static methods application design rare
Core Java
Q97. Why Java is not considered pure OOP's language ?
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 Correct / Improve 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.
Ans. This depends on entirely upon the code type. For example
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 72/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
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 Correct / Improve performance improvement code optimization Visa Inc
Ans. Constructors are used for initializing the object state once it is initialized and memory has been reserved for it.
There are no destructors in Java. Alternatively, Java provides Automatic garbage collection i.e automatically releasing the un-
referenced memory.
Help us improve. Please let us know the company, where you were asked this question :
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 73/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
OpenXava
Check everything
SPRING MVC Apache Stripes that is Best in Java
Click Here
Frequently asked. Among first few questions in the J2EE segment of interview.
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
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 74/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
Help us improve. Please let us know the company, where you were asked this question :
Like Discuss Correct / Improve 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
Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address: Subscribe
Delivered by FeedBurner
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 75/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
2 Comments Buggybread
1 Login
Sort by Best
Recommend 1 ⤤ Share
LOG IN WITH
OR SIGN UP WITH DISQUS ?
Name
ALSO ON BUGGYBREAD
Java - Interview Questions and Answers on AutoBoxing Java 8 - Interview Questions and Answers on Lambda
2 comments • 3 years ago Expressions
Dell Mercant — Autoboxing is the process of converting a primitive 1 comment • 3 years ago
type data into its corresponding wrapper class object instance. It Maximus Lagomorph — I think Q2 anwser is wrong. For what I see
involves the dynamic allocation of memory and initialization of an that expression means: helloJava8 is a function that takes a
… function specified by a lambda expression as a parameter. No
assumption …
#Java - Interview Questions and Answers for '#Deloitte' Online Practice Test - JDBC
1 comment • 10 months ago 2 comments • 3 years ago
sanhita das — good one and thanks for sharing a basic idea. vivekvermani — Thanks Zevan. This has been corrected.
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 76/77
9/26/2017 Java - Advance & Core Java Interview Question and Answers | Search Java Coding Interview Question - javasearch.buggybread.com
WEB-STAT
TRAFFIC ANALYSIS
live data
http://javasearch.buggybread.com/InterviewQuestions/questionSearch.php 77/77