java interview questions & answers by bestonlinetrainers

Upload: bestonline

Post on 03-Jun-2018

224 views

Category:

Documents


2 download

TRANSCRIPT

  • 8/12/2019 Java Interview Questions & Answers by BestOnlineTrainers

    1/12

    Java Interview Q & ABy www.bestonlinetrainers.com

    http://www.bestonlinetrainers.com/http://www.bestonlinetrainers.com/
  • 8/12/2019 Java Interview Questions & Answers by BestOnlineTrainers

    2/12

    Q11: Differentiate between a constrand a method?

    Answer:

    A member function of a class that is used to create objects ocalled a Constructor is. Its name is same as the class itself, hatype. It is invoked using the new operator. An ordinary mema class is called Method. It has its own name and a return typbe void).It is invoked using the dot operator.

    Learn Java. Ask for a free demo www.bes

    http://www.bestonlinetrainers.com/programming/java-training.htmlhttp://www.bestonlinetrainers.com/demo/index.htmlhttp://www.bestonlinetrainers.com/http://www.bestonlinetrainers.com/http://www.bestonlinetrainers.com/demo/index.htmlhttp://www.bestonlinetrainers.com/programming/java-training.html
  • 8/12/2019 Java Interview Questions & Answers by BestOnlineTrainers

    3/12

    Q12: State the purpose of garbagecollection in Java, and also when is

    Answer:

    Identifying and discarding objects that are no longer neededprogram so that their resources can be reclaimed and reusepurpose of garbage collection. When a Java object is subjeunreachable to the program in which it is used; it is subjectedcollection.

    Learn Java. Ask for a free demo www.bes

    http://www.bestonlinetrainers.com/programming/java-training.htmlhttp://www.bestonlinetrainers.com/demo/index.htmlhttp://www.bestonlinetrainers.com/http://www.bestonlinetrainers.com/http://www.bestonlinetrainers.com/demo/index.htmlhttp://www.bestonlinetrainers.com/programming/java-training.html
  • 8/12/2019 Java Interview Questions & Answers by BestOnlineTrainers

    4/12

    Q13:When is HashCode and equals(overridded ?

    Answer:

    To do equality check or use object as a key in HashMap, Hasequals() are overridden.

  • 8/12/2019 Java Interview Questions & Answers by BestOnlineTrainers

    5/12

    Q14:What is difference between Striand StringBuilder in Java?

    Answer:

    If the HashCode() is not overridded , the object will not be rethe HashMap if used as key.

  • 8/12/2019 Java Interview Questions & Answers by BestOnlineTrainers

    6/12

    Q15: State which is better: to synchrocritical section of getInstance() metwhole getInstance() method ? Answer:

    Here the answer is a bit critical as if we lock the whole methotime then this method will be called and would have to wait any object is not being created.

  • 8/12/2019 Java Interview Questions & Answers by BestOnlineTrainers

    7/12

    Q16: When String gets created usingor new() operator , what difference

    Answer:

    When a string is created with new() its created in heap and nstring pool while using literal , String can be created in String pwhich exists in Perm area of heap.

  • 8/12/2019 Java Interview Questions & Answers by BestOnlineTrainers

    8/12

    Q17: Does overriding HashCode() mhave any performance implication o

    Answer:

    Does overriding HashCode() method have any performancenot ?

  • 8/12/2019 Java Interview Questions & Answers by BestOnlineTrainers

    9/12

    Q18: In multithreaded environment w

    wrong in using HashMap? When doemethod go to infinite loop ? Answer:

    This happens during concurrent access and re-sizing.

  • 8/12/2019 Java Interview Questions & Answers by BestOnlineTrainers

    10/12

    Q19: What is thread-safety? Why is itrequired? And how to achieve threasafety in Java Applications?

    Answer:

    The legal interaction of threads with the memory in a real comdefines Java Memory Model. It also describes what behaviormulti-threaded code. It can also determine when a Thread cwrites to variables made by other threads. It also defines semvolatile, final and synchronize, that makes guarantee of visib

    operations across the Threads. In a Memory Barrier which thetype of memory barrier instructions in JMM - read barriers and

    To make the changes made by other threads visible to the cthe read barrier invalidates the local memory (cache, registethen reads the contents from the main memory .To make themade by current Thread visible to other Thread, a Write barrie

    the contents of the processors local memory to the main me

  • 8/12/2019 Java Interview Questions & Answers by BestOnlineTrainers

    11/12

    Q20: What happens if you call returnstatement or System.exit on try or cablock? Will it finally block execute? Answer:

    This is a very popular tricky Java question because many progthat finally the block always gets executed. This question chaconcept by putting return statement in try or catch block or cSystem.exit from try or catch block. In Java, this finally block weven if you put return statement in the try block or catch blowon't run even if you call System.exit form to try or catch.

  • 8/12/2019 Java Interview Questions & Answers by BestOnlineTrainers

    12/12

    Want to learn Java?Visit : http://www.bestonlinetrainers.com/programming/java-traEmail : [email protected]

    Phone : USA: +(1) 6783896789

    UK: +(44)- 2032393637

    India: +(91) 9246449191

    Ask for a free demo TODAY :

    http://www.bestonlinetrainers.com/demo/ind

    http://www.bestonlinetrainers.com/programming/java-training.htmlmailto:[email protected]://www.bestonlinetrainers.com/demo/index.htmlhttp://www.bestonlinetrainers.com/demo/index.htmlhttp://www.bestonlinetrainers.com/demo/index.htmlmailto:[email protected]://www.bestonlinetrainers.com/programming/java-training.htmlhttp://www.bestonlinetrainers.com/programming/java-training.htmlhttp://www.bestonlinetrainers.com/programming/java-training.htmlhttp://www.bestonlinetrainers.com/programming/java-training.htmlhttp://www.bestonlinetrainers.com/programming/java-training.html