- Posted on
- admin
- No Comments
Top 50 Core Java Interview Questions and Answers
Basic Java Interview Questions (1–10)
1. What is Java?
Java is a high-level, object-oriented programming language developed by Sun Microsystems, designed to have as few implementation dependencies as possible.
2. What are the main features of Java?
Object-oriented
Platform-independent
Simple and secure
Multithreaded
Robust and portable
3. What is the JVM?
JVM (Java Virtual Machine) executes Java bytecode and provides platform independence.
4. What is the difference between JDK, JRE, and JVM?
JDK: Java Development Kit (includes compiler + JRE)
JRE: Java Runtime Environment (for running Java programs)
JVM: Java Virtual Machine (part of JRE, runs bytecode)
5. Is Java a compiled or interpreted language?
Java is both. It compiles source code to bytecode (compiled) and executes it using JVM (interpreted).
6. What are the types of memory areas allocated by JVM?
Heap
Stack
Method Area
Program Counter Register
Native Method Stack
7. What is the difference between Heap and Stack memory?
Heap: Stores objects and class instances
Stack: Stores method calls and local variables
8. What is an object in Java?
An object is an instance of a class, containing data and behavior.
9. What is a class in Java?
A class is a blueprint from which individual objects are created.
10. What is a constructor in Java?
A constructor is a block of code used to initialize an object when it’s created.
11. What are the main OOPs principles in Java?
Encapsulation
Inheritance
Polymorphism
Abstraction
12. What is inheritance in Java?
It allows one class to inherit fields and methods from another.
13. What is encapsulation?
Binding data and methods that operate on the data into a single unit (class).
14. What is polymorphism?
The ability of a method or object to take many forms (method overloading/overriding).
15. What is method overloading?
Defining multiple methods with the same name but different parameters.
16. What is method overriding?
Redefining a superclass method in a subclass with the same signature.
17. What is abstraction in Java?
Hiding internal implementation details and showing only functionality.
18. What is an interface in Java?
A reference type in Java, similar to a class, that can contain only abstract methods and constants (Java 8+ allows default/static methods).
19. What is the difference between abstract class and interface?
Abstract class can have method bodies; interface cannot (pre-Java 8)
A class can implement multiple interfaces, but extend only one abstract class
20. Can you instantiate an abstract class?
No, it must be extended and implemented by a subclass.
21. What is the difference between ‘==’ and ‘.equals()’?
==
compares references; .equals()
compares object content.
22. What is the final keyword?
Used to mark variables, methods, or classes as constant/unmodifiable.
23. What is the static keyword?
Used to define class-level variables or methods that belong to the class, not instances.
24. What is the ‘this’ keyword?
Refers to the current class instance.
25. What is the ‘super’ keyword?
Refers to the parent class object and is used to access parent methods/constructors.
26. What is exception handling in Java?
A mechanism to handle runtime errors using try-catch-finally
blocks.
27. What is the difference between checked and unchecked exceptions?
Checked: Must be handled at compile time (IOException
, SQLException
)
Unchecked: Occur at runtime (NullPointerException
, ArrayIndexOutOfBoundsException
)
28. What are try, catch, finally, and throw used for?
For managing and propagating exceptions in Java programs.
29. What is garbage collection in Java?
Automatic memory management that removes unused objects.
30. How does Java achieve platform independence?
By compiling source code into bytecode that runs on the JVM.
31. What is multithreading in Java?
It allows concurrent execution of two or more threads for maximum CPU utilization.
32. How to create a thread in Java?
By extending the Thread
class
By implementing Runnable
interface
33. What is the difference between process and thread?
A thread is a lightweight sub-process; processes are heavyweight and isolated.
34. What is the lifecycle of a thread?
New → Runnable → Running → Waiting/Sleeping → Terminated
35. What are daemon threads?
Background threads that die when all user threads finish.
36. What is synchronization in Java?
A mechanism to control access to shared resources in concurrent programming.
37. What is the difference between synchronized method and block?
Method: Locks the whole object
Block: Locks a portion of code
38. What is volatile keyword?
Ensures visibility of changes to variables across threads.
39. What is deadlock?
A situation where two or more threads are blocked forever, waiting for each other.
40. How to prevent deadlock?
Avoid nested locks and acquire resources in a fixed order.
41. What is the Java Collection Framework?
A unified architecture for storing and manipulating collections of objects.
42. List vs Set in Java?
List: Allows duplicates, maintains order
Set: No duplicates, no guaranteed order
43. What is HashMap in Java?
A map-based collection for storing key-value pairs. Allows one null key and multiple null values.
44. Difference between HashMap and Hashtable?
HashMap is not synchronized
Hashtable is synchronized and slower
45. What is ArrayList?
A dynamic array that allows duplicate elements and maintains insertion order.
46. Difference between ArrayList and LinkedList?
ArrayList: Fast for random access, slow for insert/delete
LinkedList: Better for frequent insert/delete operations
47. What is Iterator?
An interface for iterating over collections (hasNext(), next(), remove()).
48. What is ConcurrentHashMap?
A thread-safe version of HashMap that allows concurrent read and limited write access.
49. What is the difference between Comparable and Comparator?
Comparable: Defines natural ordering
Comparator: Defines custom ordering
50. What is the Stream API in Java 8?
A functional-style API for processing sequences of elements using methods like filter()
, map()
, collect()
.
Popular Courses