Java interview questions for freshers and experienced candidates in India usually cover four areas: core language and OOP, the JVM and memory, the Collections Framework, and concurrency. Below are 24 real, frequently asked questions with clear answers, grouped from basic to advanced, plus a short plan to prepare. Learn the reasoning behind each answer, not just the words.
Why do Indian recruiters focus so much on core Java?
Core Java is the foundation for backend, Android, and full-stack roles, and it reveals how well you understand memory, objects, and data structures. Companies like TCS, Infosys, Wipro, Cognizant, and product startups use it to separate candidates who have merely done tutorials from those who understand how the language actually behaves. A strong grasp of fundamentals also makes learning Spring Boot, microservices, and cloud tools far easier later.
Basic Java interview questions
1. What is Java and what are its key features?
Java is a high-level, object-oriented, platform-independent programming language. Its headline feature is “Write Once, Run Anywhere”: source code compiles to bytecode that runs on any Java Virtual Machine (JVM). Other core features are automatic memory management (garbage collection), strong type safety, multithreading support, and a huge standard library.
2. What is the difference between JDK, JRE, and JVM?
The JVM (Java Virtual Machine) is the engine that executes bytecode. The JRE (Java Runtime Environment) is the JVM plus the core libraries needed to run applications. The JDK (Java Development Kit) is the full development package: it contains the JRE plus tools like the compiler (javac) and debugger. You need the JDK to write and compile code, and the JRE to run it.
3. What are the four principles of OOP in Java?
Encapsulation (bundling data and methods, hiding internal state with private fields and getters/setters), Inheritance (a class deriving properties from a parent class), Polymorphism (one interface, many forms, via overloading and overriding), and Abstraction (exposing essential behaviour while hiding implementation through abstract classes and interfaces).
4. What is the difference between == and the equals() method?
The == operator compares references (memory addresses) for objects and actual values for primitives. The equals() method compares the logical content of two objects. For example, two different String objects with the same characters return false for == but true for equals(), because String overrides equals() to compare content.
5. What is the difference between String, StringBuilder, and StringBuffer?
String is immutable: every modification creates a new object. StringBuilder is mutable and not thread-safe, so it is fast for single-threaded string building. StringBuffer is mutable and thread-safe (its methods are synchronized) but slightly slower. Use StringBuilder for loops that concatenate strings, and StringBuffer only when multiple threads share the buffer.
6. What are the primitive data types in Java?
There are eight: byte, short, int, long (integers), float and double (floating point), char (a single 16-bit Unicode character), and boolean (true/false). Primitives store actual values, not references, and are stored on the stack for local variables.
7. What is the difference between method overloading and overriding?
Overloading means defining multiple methods with the same name but different parameter lists in the same class; it is resolved at compile time (static polymorphism). Overriding means a subclass provides a new implementation of a method inherited from its parent, with the same signature; it is resolved at runtime (dynamic polymorphism).
Intermediate Java interview questions
8. What is the difference between an abstract class and an interface?
An abstract class can have both abstract and concrete methods, instance fields, and constructors, and a class can extend only one. An interface (before Java 8) had only abstract methods and constants; since Java 8 it can have default and static methods, and a class can implement many interfaces. Use an abstract class for shared code among closely related classes, and an interface to define a capability or contract.
9. What are checked and unchecked exceptions?
Checked exceptions (like IOException, SQLException) are checked at compile time and must be either caught or declared with throws. Unchecked exceptions (RuntimeException subclasses like NullPointerException, ArrayIndexOutOfBoundsException) occur at runtime and are not enforced by the compiler. Errors (like OutOfMemoryError) indicate serious problems you normally should not catch.
10. What is the difference between ArrayList and LinkedList?
ArrayList is backed by a resizable array, giving fast random access (O(1) by index) but slower insertions/deletions in the middle (O(n) due to shifting). LinkedList is a doubly linked list with fast insertion/deletion at the ends (O(1)) but slow random access (O(n)). Choose ArrayList for read-heavy work and LinkedList when you frequently add or remove at the front or middle.
11. What is the difference between HashMap and Hashtable?
HashMap is not synchronized, allows one null key and multiple null values, and is faster. Hashtable is synchronized (thread-safe), allows no null keys or values, and is a legacy class. For thread-safe maps today, prefer ConcurrentHashMap over Hashtable because it offers better concurrency through segment/bucket-level locking.
12. What is the purpose of the final, finally, and finalize keywords?
final is a modifier: a final variable cannot be reassigned, a final method cannot be overridden, and a final class cannot be extended. finally is a block that always executes after try/catch, typically to release resources. finalize() was a method called by the garbage collector before reclaiming an object; it is deprecated and should not be relied on.
13. What are autoboxing and unboxing?
Autoboxing is the automatic conversion of a primitive to its wrapper object (int to Integer), and unboxing is the reverse. It lets primitives work smoothly with collections, which store objects. Be careful: unboxing a null Integer throws a NullPointerException, and boxing in tight loops can hurt performance.
14. What is the difference between fail-fast and fail-safe iterators?
Fail-fast iterators (used by ArrayList, HashMap) throw ConcurrentModificationException if the collection is structurally modified while iterating. Fail-safe iterators (used by CopyOnWriteArrayList, ConcurrentHashMap) work on a copy or snapshot, so they do not throw that exception but may not reflect the latest changes.
15. What is the equals() and hashCode() contract?
If two objects are equal by equals(), they must return the same hashCode(). Objects that are not equal may share a hashCode (a collision), but consistent hashing improves performance in hash-based collections. If you override equals() you must override hashCode(), otherwise objects will behave incorrectly as HashMap keys or in HashSet.
Advanced Java interview questions
16. How is memory organised into heap and stack in Java?
The stack stores method call frames, local variables, and references, and is short-lived per thread. The heap stores all objects and is shared across threads; it is managed by the garbage collector. Primitive local variables live on the stack, while the objects they may point to live on the heap.
17. How does garbage collection work in Java?
The garbage collector automatically reclaims memory used by objects that are no longer reachable from any live reference. Modern JVMs use generational collection: new objects go to the young generation and are collected quickly; long-lived objects are promoted to the old generation. You cannot force collection, but System.gc() is a hint. Collectors like G1 and ZGC aim for low pause times.
18. What are functional interfaces and lambda expressions?
A functional interface has exactly one abstract method (for example Runnable, Comparator, or anything annotated with @FunctionalInterface). A lambda expression is a concise way to provide that method’s implementation, such as (a, b) -> a – b for a Comparator. Introduced in Java 8, lambdas make code shorter and enable functional-style programming with the Stream API.
19. What is the Stream API and why is it useful?
The Stream API (Java 8) lets you process collections declaratively with operations like filter, map, reduce, and collect. Streams support method chaining and can run in parallel with parallelStream(). They are lazy: intermediate operations run only when a terminal operation is invoked. They make data transformations readable but should be used judiciously in performance-critical loops.
20. What are virtual threads in Java 21?
Virtual threads, finalised in Java 21, are lightweight threads managed by the JVM rather than the operating system. Millions can run concurrently because a virtual thread is unmounted from its carrier (platform) thread during blocking calls, freeing the carrier for other work. They make high-throughput, concurrent server code easier to write without complex asynchronous frameworks.
21. What is the difference between synchronized and volatile?
synchronized provides mutual exclusion and visibility: only one thread enters a synchronized block/method at a time, and changes are visible to other threads afterwards. volatile only guarantees visibility, not atomicity: reads and writes of a volatile variable are always from main memory, but compound actions like count++ are still not thread-safe. Use volatile for simple flags and synchronized (or locks) for compound operations.
22. What are records and sealed classes?
A record (Java 16) is a concise, immutable data carrier that auto-generates the constructor, accessors, equals(), hashCode(), and toString(). A sealed class or interface (Java 17) restricts which classes may extend or implement it using the permits clause, giving you controlled, exhaustive type hierarchies that pair well with pattern matching in switch.
23. How can you create and run threads in Java?
You can extend the Thread class and override run(), or implement the Runnable interface and pass it to a Thread, which is preferred because it keeps your class free to extend something else. For real applications, use the ExecutorService and thread pools instead of creating raw threads, and use virtual threads in Java 21 for massive concurrency.
24. What do the static and transient keywords mean?
static means a member belongs to the class rather than any instance, so it is shared across all objects and can be accessed without creating an object. transient marks a field to be skipped during serialization, so its value is not saved when the object is written to a stream, useful for sensitive or derived data.
How should you prepare for a Java interview?
Start with a clear revision plan and practise code daily. Interviews reward candidates who can explain and write, not just recite.
| Stage | Focus | Time |
|---|---|---|
| Foundation | OOP, JVM/JRE/JDK, data types, strings | Week 1 |
| Collections | List, Set, Map, iterators, equals/hashCode | Week 2 |
| Advanced | Exceptions, streams, threads, memory, GC | Week 3 |
| Practice | Coding problems + mock interviews | Ongoing |
- Write small programs for every concept, do not just read; type out a HashMap example, a thread example, and a stream pipeline.
- Solve at least 30 to 50 coding problems on strings, arrays, recursion, and collections.
- Prepare to explain your resume projects: what you built, why you chose a data structure, and what you would improve.
- Do timed mock interviews and practise speaking your reasoning aloud, because communication is scored too.
- Revise Java 8 features (lambdas, streams, Optional) thoroughly, since they appear in almost every interview.
What are common mistakes candidates make?
The biggest mistake is memorising answers without understanding. Interviewers ask follow-up questions, so a rehearsed definition of polymorphism collapses when they ask you to write an example. Other frequent slips are confusing abstract classes with interfaces, forgetting the equals/hashCode contract, and being unable to explain how a HashMap works internally. Be honest when you do not know something, then reason through it aloud; that often scores better than a wrong confident answer.
Java skills open doors to backend, Android, and full-stack roles across India. For related preparation, see our Spring Boot interview questions for framework-level rounds, and build broader problem-solving with data structures interview questions and SQL query interview questions. Browse more guides in our Skills section or return to GetJobsNews for the latest jobs and career advice.
Frequently Asked Questions
Are Java interview questions the same for freshers and experienced candidates?
The core topics overlap, but freshers face more theory (OOP, JVM, collections) while experienced candidates get deeper questions on concurrency, memory management, design and real project decisions.
How many Java questions should I prepare?
Master the 24 questions below thoroughly, then practise coding on arrays, strings and collections. Depth of understanding matters far more than memorising a long list.
Do Indian IT companies still ask core Java in 2026?
Yes. TCS, Infosys, Wipro, Accenture and most product firms still test core Java fundamentals, collections and OOP even for full-stack and backend roles.
Which Java version should I mention in interviews?
Know Java 8 features (lambdas, streams) well, and be aware of modern LTS releases like Java 17 and 21 (records, sealed classes, virtual threads).
Is coding required in a Java interview?
Almost always. Expect at least one or two hands-on coding problems on strings, arrays, recursion or collections alongside the theory round.






