📌How Java Interviews Work in 2026
Java interviews in India follow a predictable path: core language and OOP, collections (especially HashMap internals), exceptions, Java 8+ streams, concurrency, the JVM, and — increasingly — modern Java 17 and 21 features such as records, sealed classes and virtual threads. Experienced candidates then get Spring Boot, microservices and system design.
This list is grouped the same way, so you can revise topic by topic. If you are still building the foundation, start with the Java developer roadmap, or join our live Java course for mock interviews with working engineers.
📌Core Java Basics
1. What are JDK, JRE and JVM?
The JVM executes bytecode. The JRE is the JVM plus the core libraries needed to run Java programs. The JDK adds the compiler (javac), debugger and tools needed to build them. Since Java 11 there is no separate JRE download — you install a JDK.2. Why is Java platform independent?
Source code compiles to bytecode, not machine code. Any operating system with a JVM can run that bytecode — "write once, run anywhere".3. Is Java pass-by-value or pass-by-reference?
Always pass-by-value. For objects, the value passed is a copy of the reference, so you can mutate the object but cannot make the caller's variable point to a new object.4. What is the difference between == and equals()?
== compares references for objects (and values for primitives). equals() compares logical equality as defined by the class.5. Why must you override hashCode() when you override equals()?
Hash-based collections usehashCode() to find the bucket and equals() to find the entry. Equal objects must have equal hash codes, otherwise a HashMap or HashSet will not find them.6. What does the final keyword do?
A final variable cannot be reassigned, a final method cannot be overridden, and a final class cannot be extended.7. What is the difference between static and instance members?
Static members belong to the class and are shared by all instances; instance members belong to each object.📌OOP
8. What are the four pillars of OOP?
Encapsulation, inheritance, polymorphism and abstraction.9. Abstract class vs interface?
An abstract class can hold state, constructors and any access modifiers; a class can extend only one. An interface defines a contract; since Java 8 it can havedefault and static methods and since Java 9 private methods, and a class can implement many. Use interfaces for capabilities and abstract classes for shared base behaviour.10. Overloading vs overriding?
Overloading is the same method name with different parameters, resolved at compile time. Overriding is a subclass redefining an inherited method with the same signature, resolved at runtime.11. What is composition and why prefer it over inheritance?
Composition builds behaviour by holding references to other objects ("has-a") instead of extending them ("is-a"). It is more flexible, avoids fragile base classes and is easier to test.12. What are the SOLID principles?
Single responsibility, open/closed, Liskov substitution, interface segregation and dependency inversion — the foundation of good low-level design. See our system design track.📌Strings
13. Why is String immutable?
For security (strings are used for class names, URLs and credentials), thread safety, safe use as HashMap keys with cached hash codes, and the string pool.14. String vs StringBuilder vs StringBuffer?
String is immutable. StringBuilder is mutable and fast. StringBuffer is mutable and synchronized, so it is slower and rarely needed.15. What is the String pool?
A special area of the heap where string literals are interned, so identical literals share one object.📌Collections
16. How does HashMap work internally?
It holds an array of buckets.hashCode() is spread and mapped to a bucket index; entries in the same bucket form a linked list, which turns into a balanced red-black tree once a bucket exceeds 8 entries (and the table has at least 64 buckets). equals() finds the exact key. When size exceeds capacity times the load factor (0.75), the table doubles and entries are redistributed.17. HashMap vs Hashtable vs ConcurrentHashMap?
HashMap is not thread-safe and allows one null key. Hashtable is synchronized on every method and legacy. ConcurrentHashMap is thread-safe with fine-grained locking and CAS, and does not allow null keys or values.18. ArrayList vs LinkedList?
ArrayList is backed by an array: fast random access, amortised O(1) appends. LinkedList is a doubly linked list with O(n) access. In practice ArrayList (or ArrayDeque for queues) wins almost every time.19. HashSet vs TreeSet vs LinkedHashSet?
HashSet is unordered and O(1). TreeSet is sorted and O(log n). LinkedHashSet keeps insertion order.20. Fail-fast vs fail-safe iterators?
Fail-fast iterators (ArrayList, HashMap) throw ConcurrentModificationException when the collection is modified during iteration. Fail-safe iterators (CopyOnWriteArrayList, ConcurrentHashMap) work on a snapshot or weakly consistent view.21. Comparable vs Comparator?
Comparable defines a class's natural order viacompareTo(). Comparator defines external, swappable orderings, for example Comparator.comparing(Employee::salary).reversed().📌Exceptions
22. Checked vs unchecked exceptions?
Checked exceptions (IOException, SQLException) must be declared or handled. Unchecked exceptions extend RuntimeException and usually signal programming errors.23. What is try-with-resources?
A try block that automatically closes any AutoCloseable resource, even if an exception is thrown — no more manual finally blocks for streams and connections.24. final vs finally vs finalize?
final is a modifier, finally is a block that always runs after try/catch, and finalize() was a GC hook that is deprecated for removal — use Cleaner or try-with-resources instead.📌Java 8+ and Functional Java
25. What is a functional interface?
An interface with exactly one abstract method, such as Runnable, Function or Predicate, which can be implemented with a lambda.26. map() vs flatMap() in streams?
map() transforms each element one-to-one. flatMap() transforms each element into a stream and flattens the results into one stream.27. Intermediate vs terminal operations?
Intermediate operations (filter, map, sorted) are lazy and return a stream. Terminal operations (collect, forEach, reduce) trigger execution.28. What is Optional for?
To represent a possibly-absent return value explicitly and avoid NullPointerException. Use it as a return type, not for fields or parameters.29. Group employees by department and count them.
Map<String, Long> countByDept = employees.stream() .collect(Collectors.groupingBy(Employee::department, Collectors.counting()));📌Concurrency
30. Process vs thread?
A process has its own memory space. Threads share the memory of their process, which makes communication cheap and synchronization necessary.31. What does volatile guarantee?
Visibility: writes by one thread are immediately visible to others, and reordering around the access is restricted. It does not make compound actions likecount++ atomic — use AtomicInteger or locks.32. synchronized vs ReentrantLock?
synchronized is simpler and automatically released. ReentrantLock adds tryLock with timeouts, interruptible locking, fairness and multiple conditions.33. What is a deadlock and how do you avoid it?
Two or more threads each wait for a lock the other holds. Avoid it by acquiring locks in a consistent order, using timeouts, or reducing shared mutable state.34. Why use ExecutorService instead of new Thread()?
Thread pools reuse threads, bound concurrency and give you futures, scheduling and clean shutdown.35. What is CompletableFuture?
An API for composing asynchronous tasks —thenApply, thenCompose, thenCombine, exceptionally — without blocking.36. What are virtual threads?
Lightweight threads managed by the JVM (final in Java 21). Millions can run on a few OS carrier threads, so blocking code scales like reactive code. Ideal for I/O-heavy servers; Spring Boot enables them withspring.threads.virtual.enabled=true. More in our Java 21 features guide.📌JVM and Memory
37. What are the JVM memory areas?
Heap (objects), stack (frames and local variables per thread), metaspace (class metadata), the code cache, and native memory.38. How does garbage collection work?
Objects unreachable from GC roots are reclaimed. Most collectors are generational: short-lived objects die young in the young generation; survivors are promoted to the old generation.39. Which GC should you use?
G1 is the default and a good balance. ZGC (generational since Java 21) gives very low pauses for large heaps. Parallel GC maximises throughput for batch jobs.40. StackOverflowError vs OutOfMemoryError?
StackOverflowError comes from too-deep recursion on a thread's stack. OutOfMemoryError means the heap, metaspace or native memory is exhausted.41. What is the JIT compiler?
It compiles hot bytecode to optimised native code at runtime, which is why Java gets faster after warm-up.📌Modern Java (17 to 21)
42. What is a record?
A concise, immutable data carrier:record Point(int x, int y) {} generates the constructor, accessors, equals, hashCode and toString.43. What are sealed classes?
Classes or interfaces that restrict which classes may extend them usingpermits, letting the compiler check that a switch covers every case.44. What is pattern matching for switch?
Switching on types with deconstruction and guards, for examplecase Circle c when c.radius() > 10 -> — final in Java 21.45. What are sequenced collections?
Java 21 interfaces that addgetFirst(), getLast() and reversed() to lists, deques and ordered sets and maps.📌Scenario Questions
46. How would you make a class immutable?
Make it final, make fields private and final, set them in the constructor, return defensive copies of mutable fields and provide no setters — or simply use a record.47. How do you implement a thread-safe singleton?
An enum singleton, or the holder-class idiom with lazy initialisation. Both are thread-safe without explicit locking.48. Your service's memory keeps growing. What do you do?
Take a heap dump (jcmd GC.heap_dump ), analyse it with Eclipse MAT or VisualVM, and look for growing collections, caches without eviction, unclosed resources or ThreadLocal leaks.49. How do you find the second-highest salary with streams?
Optional<Integer> second = salaries.stream() .distinct() .sorted(Comparator.reverseOrder()) .skip(1) .findFirst();50. What is new that you would use in a 2026 project?
Records for DTOs, sealed types with pattern matching for domain models, virtual threads for I/O-bound services, sequenced collections, and Spring Boot 3 on Java 21 or 25.📌What Comes Next
Experienced roles will move on to Spring and microservices. Prepare with Spring Framework interview questions, Spring Boot interview questions and microservices interview questions. Curious what these skills pay? Read the Java developer salary guide.
📌Practise With a Mentor
Prakalpana's Java Programming course is taught live online with an optional 1-on-1 track, real projects and mock interviews with working engineers. WhatsApp or call +91 9243078181 for a free demo.