Java Interview Questions
Basic
1. What is JDK, JRE, JVM?
2. Why JRE is removed in java 9 and its latest version?
3. Private JRE vs Public JRE?
4. What are Opensource and Freeware?
5. What is CE - Community edition in software?
6. How does java source code gets executed?
7. What is decompiler and how do decompile the class file?
OOPS
Basic OOPS
1. What is class?
2. Four main principles of OOPS language?
3. what is local variable?
4. difference between local variable and member variable?
5. scope of local variable?
6. scope of member variable?
7. Use of this.(dot) keyword in java?
8. What is abstraction?
9. What is the difference between abstraction and encapsulation?
Constructor
1. What is a constructor?
2. What is the purpose of a default constructor?
3. Does the constructor return any value?
4. Use of this() in java?
5. Use of super() in java?
6. Can you use this() and super() both in a constructor?
Inheritance
1. What is inheritance?
2. Does Java support Multiple Inheritances?
3. Why multiple inheritance is not supported in java?
4. What is the base class of all classes?
5. What is a Object class?
6. Is the constructor inherited?
7. What is super.(dot) keyword in java?
Polymorphism
1. What is Polymorphism and what are the types of it?
2. What is the method overriding?
3. What is method overloading?
4. Difference between method Overloading and Overriding.
5. What is static and dynamic binding?
6. Why method overloading is not possible by changing the return type in java?
7. Can we overload main() method?
8. Can we overload main() method?
9. Can we override the overloaded method?
10. What are Runtime Polymorphism and Compile time polymorphism?
Non-Access Specifiers
1. What is static variable?
2. What is static method?
3. Why main method is static?
4. Can we override a static method?
5. What is static block?
6. What is Abstract class?
7. Can there be any abstract method without abstract class?
8. Can you use abstract and final both with a method?
9. Is it possible to instantiate the abstract class?
10. Can we override static method?
11. Why we cannot override static method?
12. What is final variable?
13. What is final method?
14. What is final class?
15. Can you declare the main method as final?
16. Can you make a constructor final?
17. What is difference between static method and instance method?
18. Difference between abstraction and abstract class
Access Specifiers and Packages
1. What is package?
2. Do I need to import [Link] package any time? Why ?
3. Can I import same package/class twice? Will the JVM load the package twice at runtime?
4. What is static import ?
Interface
1. What is Interface in java?
2. Can you declare an interface method static?
3. Can an Interface be final?
4. What is marker interface?
5. Can we define private and protected modifiers for variables in interfaces?
6. When can an object reference be cast to an interface reference?
7. What is the difference between abstract class and interface?
Java 8,9 Interface
1. What are the functional interfaces and their use?
2. What are the default method and their uses?
3. Can we write a static method in interface?
4. Difference between static method and default method?
5. Can we write private method in interface and its uses?
Exception Handling
1. What is Exception Handling?
2. What is difference between Checked Exception and Unchecked Exception?
3. What is the base class for Error and Exception?
4. Is it necessary that each try block must be followed by a catch block?
5. What is finally block?
6. Can finally block be used without catch?
7. Is there any case when finally will not be executed?
8. What is difference between throw and throws?
9. Can an exception be rethrown?
10. Can subclass overriding method declare an exception if parent class method doesn't throw
an exception ?
11. what is exception chaining
12. can we have an empty catch block?
13. what is OutofMemoryError in java?
14. How to write custom exception in java?
15. Explain Java Exception Hierarchy?
16. What are the important methods of java Exception Class?
Threads
1. What is multithreading?
2. What is the thread?
3. What is the difference between preemptive scheduling and time slicing?
4. What does join() method?
5. What is difference between wait() and sleep() method?
6. Is it possible to start a thread twice?
7. How do you get the current thread at runtime?
8. How do you find number of active threads running?
9. How do you find the current state of a thread?
10. What are the min, max, and default priorities of the thread?
11. Can we call the run() method instead of start()?
12. What about the daemon threads?
13. Can we make the user thread a daemon thread if thread is started?
14. When should we interrupt a thread? When should we interrupt a thread
15. What is Garbage Collection?
16. What is gc()?
17. Can an unreferenced objects be referenced again?
18. What kind of thread is the Garbage collector thread?
19. What is the difference between the final and finally
20. What is the purpose of the Runtime class?
21. How will you invoke any external process in Java?
Synchronization
1. What is synchronization?
2. What is the purpose of Synchronized block?
3. Can Java object be locked down for exclusive use by a given thread?
4. What is static synchronization?
5. What is the difference between notify() and notifyAll()?
6. What is deadlock?
String Handling
1. What is the meaning of immutable in terms of String?
2. Why string objects are immutable in java?
3. How many ways we can create the string object?
4. How many objects will be created in the following code?
5. Why java uses the concept of string literal?
6. How many objects will be created in the following code?
7. What is the basic difference between string and stringbuffer object?
8. What is the difference between StringBuffer and StringBuilder ?
9. How can we create immutable class in java ?
File Handling
1. What is the difference between the Reader/Writer class hierarchy and the
InputStream/OutputStream class hierarchy?
2. What an I/O filter?
Serialization
1. What is serialization?
2. What is Deserialization?
3. What is transient keyword?
4. What is Externalizable?
5. What is the difference between Serializable and Externalizable interface?
Collections
1. What is the use of collections Framework?
2. Difference between List, Set and Map?
3. What is the difference between Collection and Collections?
4. Use of Arrays class in collections framework?
5. What is the difference between ArrayList and Vector?
6. What is the difference between ArrayList and LinkedList?
7. What is the difference between HashSet | TreeSet | LinkedHashSet?
8. What is the difference between HashMap | TreeMap | LinkedHashMap?
9. What is the difference between HashMap and Hashtable?
10. What is the advantage of Properties file?
11. What are legacy classes?
12. Which collection is used to store unique value?
13. How to sort elements in an ArrayList without removing duplicate value?
14. How to sort and remove duplicate elements in an ArrayList?
15. What is the difference between Iterator and ListIterator?
16. What is the difference between Iterator and Enumeration?
17. What is the difference between Comparable and Comparator?
18. How to synchronize List, Set and Map elements?
19. What is the advantage of generic collection?
20. What is the Dictionary class?
More Core Java Questions
1. Which access modifiers can be applied to the inner classes?
2. If I don't provide any arguments on the command line, then the String array of Main
method will be empty or null?
3. What if I write static public void instead of public static void?What is the default value of
the local variables?
4. Can we execute a program without main() method?
5. What if the static modifier is removed from the signature of the main method?
6. What is composition?
7. What is difference between aggregation and composition?
8. Why Java does not support pointers?
9. What is object cloning?
10. Can you have virtual functions in Java?
11. What is covariant return type?
12. Why can’t I do [Link] () ? Arrays are just objects, right?
13. What does the hashCode() method?
14. Why we override equals() method?
15. Override toString method?
16. Override clone method?
17. Methods in Object class?
Questions yet to be updated for 1.7, 1.8, 1.9 and java concurrency..
Others
1. what is platform?
2. what is the main difference between java platform and other?
3. what is the difference between object oriented programming lang and object based
programming lang?
4. what is difference between static method and instance?
5. what is shutdown hook?
6. what is nested class?
7. what is the purpose of toString() method in java?
8. what is nested interface?
9. can a class have an interface?
10. can we access the non-final local variable, inside the local inner?
11. difference between nested classes and inner?
12. What is hash-collision in Hashtable and how it is handled in Java?
13. What is the default size of load factor in hashing based collection?
14. How can I put all my classes and resources into one file and run it?