This guide provides categorized Java interview questions with concise answers to help prepare for technical interviews across all levels. Dive deeper into any topic where you have doubts.
Beginner Level Questions
- What is Java? A high-level, object-oriented, platform-independent programming language developed by Sun Microsystems (now Oracle).
- What is the JVM? JVM (Java Virtual Machine) runs Java bytecode and provides platform independence.
-
Difference between JDK, JRE, and JVM?
JDK: Java Development Kit (compiler + tools)
JRE: Java Runtime Environment (JVM + libraries)
JVM: Java Virtual Machine (runs the bytecode) - What are primitive data types in Java? byte, short, int, long, float, double, boolean, char
- What is a class and an object? A class is a blueprint. An object is an instance of a class.
-
What is the difference between == and .equals()?
==compares references;.equals()compares content (if overridden). - What is method overloading? Defining multiple methods with the same name but different parameter lists.
- What is a constructor? A special method called when an object is created; used to initialize values.
- What is the default value of int, boolean, and object references? int: 0, boolean: false, object references: null
-
What is the main method signature?
public static void main(String[] args)
Intermediate Level Questions
-
What is inheritance?
A mechanism where one class acquires properties/methods of another class using
extends. - What is polymorphism? Ability of an object to take many forms: compile-time (overloading), runtime (overriding).
- What is method overriding? A subclass provides a specific implementation of a method already defined in its superclass.
- What is an interface? A contract with abstract methods. A class implements an interface to follow that contract.
- Difference between abstract class and interface? Abstract class can have state and constructors; interface is pure contract. Interfaces support multiple inheritance.
- What are access modifiers in Java? public, private, protected, default — define scope of visibility.
- What is the 'this' keyword? Refers to the current object instance.
- What is the final keyword? Used to declare constants, prevent method overriding or inheritance.
- What is exception handling? Mechanism to handle runtime errors using try-catch-finally blocks.
-
Difference between checked and unchecked exceptions?
Checked: compile-time (e.g., IOException)
Unchecked: runtime (e.g., NullPointerException)
Advanced Level Questions
- What is multithreading in Java? Ability to run multiple threads (units of execution) concurrently.
- What is the difference between process and thread? A process is an independent program; a thread is a lightweight unit within a process.
- What is synchronization? Technique to control access to shared resources in multithreading.
- What is the volatile keyword? Ensures visibility of changes to variables across threads.
-
What is the difference between ArrayList and LinkedList?
ArrayList: fast for indexing, slow for insert/delete
LinkedList: fast for insert/delete, slow for indexing - What is HashMap? How does it work internally? Stores key-value pairs using a hash function and buckets. Uses equals() and hashCode().
- What is the difference between HashMap and Hashtable? HashMap is not synchronized; Hashtable is thread-safe but slower.
- What is the use of transient keyword? Prevents fields from being serialized.
- What is reflection in Java? Allows inspection and modification of classes, methods, and fields at runtime.
-
What are lambda expressions?
Introduced in Java 8 to provide concise syntax for functional interfaces (e.g.,
(a, b) -> a + b).
These categorized questions are commonly asked in Java interviews and provide a solid foundation. Practice and deeper exploration of each topic are keys to excelling in interviews.