Languages · 24 concepts
Core Java
Get ready for Java interviews: language rules, collections, concurrency, the JVM, modern Java and real production incidents.
Asked in these mock interviews
Part 1 · 4 concepts
Objects and language basics
- 01
Pass by value and boxed numbers
Java always passes by value. For an object, the value is a copy of the reference. Boxed numbers (Integer, Long) are objects, so == compares references and gives wrong…
- 02
Strings: the pool, equals and building text
A String is immutable. Literals share one pooled object, so == works by luck. Use equals for content and StringBuilder when you build text in a loop.
- 03
final, finally, static and interface rules
The keywords final, finally and static each have a precise meaning. Default methods in interfaces can clash, and then the class must choose.
- 04
equals, hashCode and objects in hash collections
If two objects are equal, they must have the same hash code. Break that, or change a key field after adding it to a set, and objects get lost in HashSet and HashMap.
Part 2 · 5 concepts
Types, errors and modern syntax
- 05
Immutable classes
An immutable class has final fields that point to immutable data. Copy mutable inputs in and protect them out, or the object can still change.
- 06
Records, sealed types and pattern matching
Records are short immutable data classes. Sealed types list every allowed subtype, so a switch over them needs no default and the compiler finds missing cases.
- 07
Exceptions and try-with-resources
Checked exceptions force callers to handle errors; unchecked ones do not. Close resources with try-with-resources, never with a hand-written finally.
- 08
Lambdas, functional interfaces and Optional
A lambda supplies the one abstract method of a functional interface. Lambdas capture values, not variables. Optional is for return values, not for fields.
- 09
Streams and collectors, and when not to go parallel
Streams group, filter and aggregate data in memory. Collectors.toMap fails on duplicate keys. A parallel stream uses a shared pool and is rarely right in a web handler.
Part 3 · 4 concepts
Collections and generics
- 10
How HashMap works inside
A HashMap is an array of buckets. The key's hash picks the bucket, equals finds the key, and long buckets turn into trees. It is not thread-safe.
- 11
Choosing a List, and removing items safely
ArrayList is the default list. LinkedList is rarely better. Removing from a list inside a for-each loop throws or skips items.
- 12
Ordered maps, TreeMap and comparators
TreeMap and TreeSet use a comparator, not equals. LinkedHashMap keeps order and can build an LRU cache. Comparators must not overflow or drop items.
- 13
Generics, wildcards and type erasure
Generics are invariant, so a List<Integer> is not a List<Number>. Wildcards allow read-only or write-only views. Types are erased at runtime.
Part 4 · 5 concepts
Concurrency
- 14
Threads, states and wait/notify
A thread has six states. Reading them in a thread dump tells you where a service is stuck. wait and notify coordinate threads, and always need a while loop.
- 15
volatile, synchronized and happens-before
volatile gives visibility and ordering but not atomic compound actions. synchronized gives mutual exclusion and visibility. Lazy singletons need volatile or the holder…
- 16
Thread-safe counters and maps
ConcurrentHashMap is safe per call, but get-then-put is not atomic. Use merge, computeIfAbsent, LongAdder or a lock for the whole action, and never run slow code inside…
- 17
Executors and thread pools
Pool size comes from arrival rate and wait time. Default pools have unbounded queues. submit hides exceptions. A pool task must never wait for another task in the same…
- 18
CompletableFuture and virtual threads
Run parallel calls on a chosen executor with timeouts. Virtual threads make blocking cheap, but you still need limits, and on older JDKs synchronized pins the carrier…
Part 5 · 4 concepts
JVM, memory and Java versions
- 19
Heap, stack, Metaspace and garbage collection
Objects live in the heap, frames in thread stacks and class data in Metaspace. The collector frees objects that cannot be reached from GC roots. Humongous objects in G1…
- 20
OutOfMemoryError, leaks and heap dumps
OutOfMemoryError has several kinds, each with a different first check. Leaks come from static collections, caches without limits and unclosed listeners. A heap dump…
- 21
The JVM in containers and at startup
In a small container the JVM may pick Serial GC and a small heap. Native memory can pass the container limit while the heap looks fine. New pods are slow until the JIT…
- 22
Java versions, upgrades and dependency conflicts
Know what Java 17, 21 and 25 added, how to argue for an upgrade, what usually breaks, and how to fix a NoSuchMethodError caused by two library versions.
Part 6 · 2 concepts
Java in production
- 23
Diagnosing CPU, blocked threads and thread leaks
Take two or three thread dumps a few seconds apart, then read them. A thread in the same place every time is stuck. Match hot OS threads to Java threads, and group…
- 24
Leaked files, noisy logs and telling the story
Unclosed files and streams, runaway logs and slow jobs have simple causes. A good incident answer has impact, evidence, a mitigation, a root cause and prevention.
Your first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.