Being in IT industry for almost 15 years, I have come across some most important Core Java Interview questions, which are frequently asked in most of the interviews by MNCs. Based on my experience, I have tried to provide answers in easy words and point to point.
This is first set of Core Java Interview questions. Very soon we will come up with 2nd set and FAQs for Advanced Java as well.
Hope it will be helpful !
Q1. What is System.out.println?
- System = final System class
- out      =  static PrintStream object
- println = method of a printstrem class
Q2. What is difference between abstract class and interfaces.
- abstract class can provide implementation, interface has no implementation at all
- used using extends, used using implements
- both can not be instantiated
Q3. What will be the output of following code snippet?
public class MyTests
{
public static void main(String args[])
{
String s=null;
System.out.println(s.hashCode());
}
}
The program will be compiled without any errors, at run time it will throw NullPointerException.
Q4. What will be the output of following code snippet.
public class MyTests
{
private static void main(String args[])
{
}
}
The program will be compiled without any errors, at run time it will give an Error saying xMain Method not publicx
Q5. What is difference between sleep() and wait()?
When we say sleep(2000), then the thread sleeps for exact 2 seconds, but when we say wait(2000), the  thread might wake up on receiving notify() OR notifyall() call.
Q6. What are serializable, externalizable interfaces?
These are interfaces used while serialization process. Serialization is a process in which object is converted in byte stream to transfer over network. Serializable acts as marker interface and externalizable is specialization of serializable interface with methods like readExternal, writerExternal, which gives you more control over serialization process.
Q7. How threds are created?
In java threads can be created either by extending Thread class Or implementng Runnable Interface.We need to override run() method.
Q8. Differenes between Vector and ArrayLists
- ArrayLists are not synchronized while vectors are synchronized.
- By default ArrayList grows by 50% Â and Vector grows by 100%.
Q9. What is difference between HashMap and HashTable
- HashTable is synchronized and HashMaps are unsynchronizd
- HashTable do not allow null as a key, HashMap allow null as key