Sei sulla pagina 1di 4

7/15/13

Java FAQs Top 30 Core-Java interview questions and answers | thecafetechno.com

Search:
Search

Menu

Search:
Search

Home Hibernate Spring English english language usage sample letters and emails for all occasions Life Science About Us Contact Us Join Us

Java FAQs Top 30 Core-Java interview questions and answers


13. April 2012 Comments Off Categories: interview questions, java core

Like

12

Tw eet

Question: Explain Constant folding optimization with an example. Ans: The Java compiler uses Constant folding technique for code optimization. Since final variables cannot change, they can be optimized. Javap command and Java Decompiler are handy tool Read More Question: Explain the concept of method overloading and overriding with an example. Ans: Method overriding happens at runtime. This is also called runtime polymorphism because the compiler does not and cannot know which method to call. Instead, the JVM must determine it while the code is running Read More Question: What are immutable objects in Java? Can we change the value of an immutable object? Ans: An object is considered to be immutable if its value cannot change after it is created. Immutable objects are particularly very useful in multi-threaded applications. Since they cannot change state, they wont get currupted by thread interference or observed in an inconsistent state. Read More Question: How can we create an immutable object in Java? Does all properties of immutable object need to be final?
thecafetechno.com/tutorials/interview-questions/most-frequently-asked-core-java-interview-questions-and-answers/ 1/4

7/15/13

Java FAQs Top 30 Core-Java interview questions and answers | thecafetechno.com

Ans: To create an immutable object You need to make the class final and all its members final so that once objects gets created no one can modify its state. Read More Question: What is the difference between String, StringBuffer and StringBuilder? Ans: String class objects are immutable whereas StringBuilder and StringBuffer objects are mutable. Use String class if the object value is not going to change, because String objects are immutable. Read More Question: Explain String Constant Pool with an example. Ans: In Java, String objects are very special (because they are immutable) because their values are treated in a special way. For efficient use of memory, JVM manages String values (especially the String literals) by putting them in a special area of memory called the String constant pool. Read More Question: What are the advantages of String Immutability in Java ? Ans: It simplifies multithreaded programming since reading from a type that cannot change is always safe to do concurrently. We can share duplicates by pointing them to a single instance. Read More Question: What are the best practices related to the Java Collection framework? Ans: In general, collections are not immutable objects. So care should always be taken not to unintentionally expose the collection fields to the caller. The caller may not perform any necessary validation. Read More Question: What is the difference between HashMap and HashTable? Ans: Hashtable is a data structure that retains values of key-value pair. It doesnt allow null for both the keys and the values. You will get a NullPointerException if you add null value. It is synchronized. So it comes with its cost. Only one thread can Read More Question: What is the difference between a process and a thread? Ans: A processor executes threads, not processes, so each application has at least one process, and a process always has at least one thread of execution, known as the primary thread. Read More Question: Can we override a static method? Ans: The static methods cannot be overridden. If a subclass defines a static method with the same signature as a static method in the superclass, the method in the subclass hides the one in the Read More Question: Why dont we call run() method directly? Why do we call start() method which in turn calls run() method? Ans: The proper way to start a new thread is to call the start() method instead of calling the run() method directly, because run() method is not a regular class method. It should only be called by the virtual machine (JVM). Writing thread classes Read More Question: What is synchronization in java? Can a java class be synchronized? Ans: Synchronization is a process of controlling the access of shared resources by the multiple threads in such a manner that only one thread can access a particular resource at a time. In non-synchronized multithreaded application, it is possible for one thread to modify a shared Read More
thecafetechno.com/tutorials/interview-questions/most-frequently-asked-core-java-interview-questions-and-answers/ 2/4

7/15/13

Java FAQs Top 30 Core-Java interview questions and answers | thecafetechno.com

Question: Who throws IllegalMonitorStateException? What is the cause of it? Ans: This exception is thrown when you try to call any of these methods [ wait(), notify() or notifyAll() ] for an Object from a point in your program where you are NOT having a lock on that object Read More Question: What is the difference between Iterator and ListIterator? Ans: The interface Java.util.ListIterator extends java.util.Iterator interface. In addition to methods declared by java.util.iterator, it enables programmer to traverse the list in any direction along with Read More Question: Explain the purpose and use of ThreadLocal class in Java. Ans: This class provides thread-local variables. These variables differ from their normal counterparts in that each thread that accesses one (via its get or set method) has its own, independently initialized copy of the variable. Read More Question: What are the advantages of threadlocal in java? Ans: ThreadLocal is an alternative to the usage of global variable passed from methods to methods as argument or static variable (visible within the current ClassLoader). However, unlike global or static variables, the ThreadLocal scope is limited to the Read More

About the author: admin


Comments closed

You May Also Like


thecafetechno.com/tutorials/interview-questions/most-frequently-asked-core-java-interview-questions-and-answers/ 3/4

7/15/13

Java FAQs Top 30 Core-Java interview questions and answers | thecafetechno.com

Which are the different method name resolvers in MultiActionController ? PropertiesMethodNameResolver example in Spring MVC ParameterMethodNameResolver example in Spring MVC InternalPathMethodNameResolver example Spring MVC When and how to use MultiActionController in Spring MVC? Get our Articles via Email.

You can get our articles in your inbox each day for free. Just enter your email below:
Subscribe

Recent Posts Which are the different method name resolvers in MultiActionController ? PropertiesMethodNameResolver example in Spring MVC ParameterMethodNameResolver example in Spring MVC InternalPathMethodNameResolver example Spring MVC When and how to use MultiActionController in Spring MVC? 2013 thecafetechno.com. All rights reserved. Powered by Thecafetechno.

thecafetechno.com/tutorials/interview-questions/most-frequently-asked-core-java-interview-questions-and-answers/

4/4

Potrebbero piacerti anche