Java Comparators and Ordered Collections
Why TreeSet and TreeMap drop elements when a Comparator disagrees with equals, and how to write comparators that obey the full contract.
Focused explanations and longer guides, with worked scenarios, common mistakes and interview exercises across every chapter.
Showing 121–144 of 200 articles
Why TreeSet and TreeMap drop elements when a Comparator disagrees with equals, and how to write comparators that obey the full contract.
How exceptions travel through CompletableFuture chains, when to use exceptionally, handle or whenComplete, and why causes arrive wrapped.
Why check-then-act on ConcurrentHashMap still races, and how merge, compute and putIfAbsent make compound updates atomic per key.
The equals and hashCode contract explained: why equal objects need equal hash codes, how HashMap uses both, and how to write a correct pair.
Checked vs unchecked exceptions in Java, where to catch, when to wrap with a cause, and how to avoid swallowing failures at the wrong layer.
How Java memory leaks happen despite garbage collection: GC roots, reachability, retained size, and finding the reference chain in a heap dump.
How to make a class immutable in Java: final fields, no setters, defensive copies of mutable inputs and outputs, and safe publication.
When to use Instant, LocalDateTime, ZonedDateTime and OffsetDateTime, and how daylight saving gaps and overlaps break naive date code.
What synchronized guarantees in Java: mutual exclusion, visibility and reentrancy, plus how to guard multi-field invariants with one lock.
Why one Java thread may never see another's write, what volatile guarantees, and how happens-before rules make publication safe.
When Java 21 virtual threads help, why they do not speed up CPU-bound work, and how pinning, pooling and resource limits trip teams up.
Why [...arr] and slice() copy the array but not the objects inside it, and how to choose a targeted update, structuredClone or JSON safely.
How Array.prototype.reduce works, why the initial value matters for empty arrays, and when mutating the accumulator is safe or quadratic.
Why await inside forEach does not wait, how for...of runs tasks in sequence, and how to run async work in parallel with a concurrency limit.
One click listener on a parent can serve rows added later. How closest(), contains() and composedPath() keep delegation from misfiring.
A forgotten listener kept 200 models and 76 MB alive in Node. How to prove a leak with GC and heap snapshots, then break the retaining path.
Why ES module imports see later changes to exported variables, why CommonJS copies values, and how live bindings affect circular imports.
How promise finally() passes results and errors through, when a finally callback overrides the outcome, and how try/finally compares.
Why WeakMap keys do not keep objects alive, why WeakMaps cannot be iterated, and how to attach caches and private data without leaking memory.
Why a 170 ms synchronous loop in one Node.js request delays every other request, how to measure loop delay, and when to chunk or use workers.
Why decoding each chunk with toString() corrupts non-ASCII text, how StringDecoder fixes it, and when Node.js bytes must never become strings.
How a filename becomes shell injection with exec, why execFile and spawn with argument arrays avoid it, and the -- trick for argument injection.
Where async errors escape try/catch in Node.js, why a floating promise kills the process, and how to wrap causes and catch at one boundary.
Why path.join doesn't stop ../ traversal, how a startsWith check and a symlink both leak files, and a Node.js containment check that holds up.
No notes match that… try another filter.