java-interview-questions-&-answers by bestonlinetrainers.pptx

Upload: bestonline

Post on 03-Jun-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

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

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

    2/12

    Q1: To implement key Object in Haswhich two methods are used?

    Answer:

    In HashMap, to use any object as Key it must implement equals HashCode method in Java.

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

    3/12

    Q2:What is an immutable object? Man immutable object?

    Answer:

    Objects that cannot be modified once created are immutable JAVA. A new object can be resulted due to any modification inobject. For example, in JAVA, String is immutable. In order to prefrom overriding methods in Java which can compromise Immutimmutable object are mostly final in JAVA. This same functionaliachieved by making member as non final but private and not m

    except in constructor.

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

    4/12

    Q3:WState the difference betwecreating String as new() and lite

    Answer:

    When string is created with new() Operator, its created in a hadded into string pool whereas using literal String are createditself which exists in PermGen area of heap, Example: String sString("Test"); It does not put the object in String pool , but neecalled String.intern() method which is used to put them into Sexplicitly. Its only then thats it create String object as String li

    String s = "Test" Java automatically put that into String pool

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

    5/12

    Q4:What is difference between Strinand StringBuilder in Java?

    Answer:

    Classic Java questions can seem to be tricky and very easy. IStringBuilder is introduced and the only difference between bthat StringBuffer methods are synchronized while StringBuildesynchronized.

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

    6/12

    Q5: Overriding HashCode() methoddifference in performance implicatio

    Answer:

    Yes .A poor HashCode function will result in frequent collision which eventually increase time for adding an object into Has

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

    7/12

    Q6: While writing stored procedure or accstored procedure from java how is the errcondition handled?

    Answer:

    This is one of the tough questions normally asked in Java interstored procedure should return error code if some operation stored procedure itself fails than catching SQLException is theleft .

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

    8/12

    Q7: At the compile time are the imports cfor validity? That is, will the code containiimport such as java.lang.ABCD compile u

    Answer:

    Yes. The imports are checked for the semantic validity at theThe above line of import will not compile if it has the code, asaying, cannot resolve symbol.

    Symbol: class ABCD

    Location: package io

    Import java.io.ABCD;

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

    9/12

    Q8: State difference betweenExecutor.submit() and Executer.execmethod? Answer:

    When looking at exception handling, there is a difference. If tthrows an exception and if it was submitted with the executeexception will go to the uncaught exception handler (that is explicitly is not provided, the default one will just print the staSystem.err). If the task is submitted with any thrown exceptionexception or not, is then part of the task's return status. And fo

    was submitted with submit and that terminates with an excepfuture.get will re-throw this exception wrapped in an Executio

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

    10/12

    Q9: What is the difference betweenand abstract factory pattern?

    Answer:

    One more level of abstraction is provided by Abstract Factorfactories from each Abstract Factory responsible for the creadifferent hierarchies of objects based on type of factory are For example; Abstract Factory extended by AutomobileFactUserFactory, RoleFactoryetc.For every object created in thatindividual factory would be responsible.

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

    11/12

    Q10: Define Singleton? Which is bettmake whole method synchronized ocritical section synchronized? Answer:

    Singleton in JAVA is a class with just one instance in the wholeapplication. One such example is java.lang.Runtime is a Sing.With the introduction Enum by Java 5, creating a Singleton isthan being tricky as earlier.

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

    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