100 questions covering the areas Java interviews actually test, grouped by topic with a one-line
hint for each. Read through a category, then practice answering out loud in a
live mock interview — reading an answer and
producing one under pressure are very different skills.
Core Java Basics
What's the difference between JDK, JRE, and JVM?JDK builds code, JRE runs it, JVM executes bytecode.
Why is Java called "platform independent"?Bytecode runs on any JVM, regardless of OS.
What's the difference between == and .equals()?== compares references; .equals() compares logical value.
Why are Strings immutable in Java?Security, caching (string pool), and thread-safety.
What is the String pool?A cache of literal strings reused to save memory.
Difference between String, StringBuilder, and StringBuffer?Immutable vs mutable; StringBuffer is synchronized, StringBuilder isn't.
What are wrapper classes?Object versions of primitives, e.g. Integer for int.
What is autoboxing/unboxing?Automatic conversion between primitives and their wrapper types.
What's the difference between final, finally, and finalize()?Keyword, block that always runs, and a deprecated cleanup hook.
What are the access modifiers in Java?private, default, protected, public — narrowest to widest.
What is the difference between a class and an object?Class is the blueprint; object is the instance.
What is a constructor, and can it be overloaded?A special method that initializes an object; yes, constructors can be overloaded.
What's the difference between static and instance methods?Static belongs to the class; instance requires an object.
What is the this keyword used for?Refers to the current object instance.
OOP & Design
What are the four pillars of OOP?Encapsulation, abstraction, inheritance, polymorphism.
What's the difference between abstraction and encapsulation?Abstraction hides complexity; encapsulation hides internal state.
What's the difference between an interface and an abstract class?Interfaces define contracts; abstract classes can share partial implementation.
Can an interface have method bodies?Yes, via default and static methods since Java 8.
What is method overloading vs overriding?Overloading: same name, different params, compile-time. Overriding: same signature, runtime.
What is polymorphism, with a real example?One interface, many implementations — e.g. List backed by ArrayList or LinkedList.
Why does Java not support multiple inheritance of classes?Avoids the "diamond problem" of ambiguous method resolution.
What is composition vs inheritance, and when do you prefer one?Composition ("has-a") is generally more flexible than inheritance ("is-a").
What is the Singleton pattern, and how do you implement it safely?One instance per JVM; use an enum or double-checked locking for thread safety.
What is dependency injection?Supplying an object's dependencies from outside rather than creating them internally.
What is the Builder pattern used for?Constructing complex objects step by step, especially with many optional fields.
What does "program to an interface, not an implementation" mean?Depend on abstractions so implementations can change without breaking callers.
Collections & Generics
What's the difference between List, Set, and Map?Ordered duplicates, unique elements, and key-value pairs respectively.
Difference between ArrayList and LinkedList?Array-backed (fast random access) vs node-based (fast insert/delete).
Difference between HashMap, LinkedHashMap, and TreeMap?No order, insertion order, and sorted order.
How does HashMap handle collisions?Chained buckets (linked list or tree for large buckets since Java 8).
What's the difference between HashSet and TreeSet?Unordered vs sorted, backed by HashMap vs a red-black tree.
What makes an object usable as a HashMap key?Consistent, correctly overridden hashCode() and equals().
Difference between Comparable and Comparator?Comparable defines natural order on the class; Comparator defines external, custom order.
What is a ConcurrentModificationException, and how do you avoid it?Thrown when a collection is modified while iterating; use an Iterator.remove() or a concurrent collection.
What are generics, and why use them?Compile-time type safety without casting.
What is type erasure?Generic type info is removed at compile time and only enforced statically.
What's the difference between Iterator and ListIterator?ListIterator supports bidirectional traversal and element modification.
What is the difference between fail-fast and fail-safe iterators?Fail-fast throws on concurrent modification; fail-safe iterates over a snapshot/copy.
When would you use an ArrayDeque over a Stack?ArrayDeque is faster and not legacy-synchronized like Stack.
What's the difference between Queue and Deque?Deque supports insertion/removal from both ends.
Exception Handling
What's the difference between checked and unchecked exceptions?Checked must be declared/caught; unchecked (RuntimeException) are not enforced by the compiler.
What's the difference between Error and Exception?Errors are unrecoverable JVM issues; exceptions are recoverable application issues.
What is try-with-resources, and why use it?Automatically closes resources implementing AutoCloseable.
Can you have a try block without a catch block?Yes, paired with finally or try-with-resources.
What happens if an exception is thrown inside a finally block?It suppresses any exception from the try block.
How do you create a custom exception?Extend Exception or RuntimeException and add context fields.
What is exception chaining?Wrapping a lower-level exception as the cause of a higher-level one.
Why is catching Exception or Throwable broadly discouraged?It hides real failures and can swallow programming errors.
Multithreading & Concurrency
What's the difference between a process and a thread?A process has its own memory space; threads share the process's memory.
How do you create a thread in Java?Extend Thread or implement Runnable/Callable.
What does the synchronized keyword do?Ensures only one thread executes a block/method on a given lock at a time.
What is a race condition?Two threads access shared state concurrently and the outcome depends on timing.
What is a deadlock, and how can it happen?Two or more threads wait on each other's locks indefinitely.
What's the difference between wait()/notify() and sleep()?wait/notify release the lock for inter-thread signaling; sleep just pauses the thread.
What is the volatile keyword for?Guarantees visibility of a variable's latest value across threads.
What's the difference between volatile and synchronized?Volatile only guarantees visibility; synchronized also guarantees atomicity/mutual exclusion.
What is the Java Memory Model, briefly?Defines how/when changes made by one thread become visible to others.
What is an ExecutorService?A managed thread pool abstraction for running tasks asynchronously.
What's the difference between Runnable and Callable?Callable can return a value and throw checked exceptions; Runnable can't.
What is a Future, and what does it give you over a raw thread?A handle to a result computed asynchronously, with blocking/cancellation support.
What are atomic classes like AtomicInteger for?Lock-free thread-safe operations on a single variable.
What is the difference between ConcurrentHashMap and a synchronized HashMap?ConcurrentHashMap uses finer-grained locking for much better concurrent throughput.
Java 8+ (Streams, Lambdas, Functional)
What is a lambda expression?A concise, anonymous implementation of a functional interface.
What is a functional interface?An interface with exactly one abstract method, e.g. Runnable.
What's the difference between map() and flatMap()?map transforms elements; flatMap also flattens nested streams/collections.
What is a Stream, and is it reusable?A lazy pipeline over a data source; no, a consumed stream can't be reused.
Difference between intermediate and terminal stream operations?Intermediate ops are lazy (map, filter); terminal ops trigger execution (collect, forEach).
What does Optional solve?Makes the possibility of "no value" explicit, reducing NullPointerExceptions.
What is a method reference, e.g. String::toUpperCase?Shorthand syntax for a lambda that just calls an existing method.
What's the difference between Predicate, Function, and Consumer?Boolean test, transform-and-return, and accept-with-no-return, respectively.
What does Collectors.groupingBy() do?Groups stream elements into a Map keyed by a classifier function.
What is a parallel stream, and when is it risky?Splits work across threads; risky with shared mutable state or small datasets (overhead).
What are default and static methods on interfaces for?Let interfaces evolve without breaking existing implementers.
What is the difference between var and explicit typing?var infers the type at compile time; it's still statically typed, not dynamic.
What are Java records (Java 16+)?Concise immutable data carrier classes with auto-generated boilerplate.
What is a sealed class/interface for?Restricts which classes may extend or implement it.
JVM, Memory & Performance
What's the difference between stack and heap memory?Stack holds method calls/locals; heap holds objects.
What is garbage collection, and how does it decide what to collect?Automatic reclamation of memory no longer reachable from GC roots.
What is the difference between minor GC and major/full GC?Minor cleans the young generation; major/full also cleans the old generation.
What causes a StackOverflowError?Excessive recursion exceeding the stack's fixed size.
What causes an OutOfMemoryError?Heap (or metaspace) exhausted, often from a memory leak or undersized heap.
What is a memory leak in Java, given it has garbage collection?Objects unintentionally kept reachable (e.g. via static collections) so GC can't reclaim them.
What are strong, weak, and soft references?Normal, GC'd eagerly when only weakly reachable, and GC'd only under memory pressure.
What is JIT compilation?The JVM compiles hot bytecode paths to native machine code at runtime.
What's the difference between the Metaspace and the old PermGen?Metaspace (Java 8+) uses native memory instead of a fixed-size heap region.
How would you diagnose a memory leak in a running Java app?Heap dump analysis (e.g. via a profiler) to find objects with unexpected retention.
What's the difference between == and object identity for Integer caching?Small boxed integers (-128 to 127) are cached, so == can misleadingly return true.
What is class loading, and what are the main class loaders?Bootstrap, platform/extension, and application (system) class loaders, in a delegation hierarchy.
Spring Boot & Microservices Basics
What problem does Spring's dependency injection solve?Decouples object creation from object use, easing testing and configuration.
What's the difference between @Component, @Service, and @Repository?Functionally similar; they signal intent and enable layer-specific behavior (e.g. exception translation).
What does @SpringBootApplication actually do?Combines auto-configuration, component scanning, and configuration annotations.
What's the difference between @RestController and @Controller?@RestController implies @ResponseBody on every method, returning data not views.
What is Spring Boot auto-configuration?Sensible default beans configured automatically based on the classpath.
What's the difference between a monolith and a microservices architecture?Single deployable unit vs many independently deployable, loosely coupled services.
What is an API gateway used for in microservices?A single entry point handling routing, auth, and rate limiting across services.
How do microservices typically handle failures in downstream calls?Timeouts, retries, and circuit breakers to avoid cascading failure.
SQL Basics for Java Developers
What's the difference between INNER JOIN and LEFT JOIN?Inner join returns only matches; left join keeps all left-side rows.
What is a primary key vs a foreign key?Uniquely identifies a row vs references a primary key in another table.
What is database indexing, and what's the tradeoff?Speeds up reads at the cost of extra storage and slower writes.
What is the N+1 query problem in an ORM like Hibernate/JPA?One query per related row instead of a single joined/batched query, killing performance.
Reading these is step one. Answering them live is step two.
Run a free mock interview and get scored feedback on how you'd actually answer these under pressure.