Advanced
Advanced & Idiomatic: Overview
Chapter 6 of the Java book: functional Java, concurrency and the memory model, I/O, modern idioms, shipping and localization. Covers the Streams API, threads and the happens-before rule, high-level concurrency and virtual threads, the JIT and GC, NIO.2 files, how the modern features combine into data-oriented design, testing, builds and packaging, and localization with Locale, resource bundles and MessageFormat. Every example is compiled and run.
Suggest an editAdvanced & Idiomatic: Overview
Welcome to Chapter 6, the summit. You now have the full language and the standard library behind you. These nine lessons cover what separates competent Java from idiomatic, production-grade Java:
- declarative data processing with streams;
- the hard truths of concurrency — races, coordination, and the Java Memory Model;
- how the JVM actually runs your code and reclaims its memory;
- modern file I/O;
- how the modern type-system features compose into one coherent style;
- the testing, tooling and packaging that ship your code;
- and the localization that lets it speak its readers' languages.
There are nine lessons, in this order:
- Functional Java & the Streams API — lazy pipelines, collectors,
Optional, and the parallel-stream hazard. - Concurrency: the Basics — what a thread is, race conditions,
synchronized, and happens-before. - Concurrency: Coordination —
wait/notify, a real deadlock and its escapes,ReentrantLock, latches, semaphores, andBlockingQueue. - Concurrency: High-Level & Virtual Threads — executors, atomics,
CompletableFuture, and virtual threads. - The Java Memory Model & Performance —
volatile, happens-before in depth, safe publication, the JIT, and garbage collection. - I/O, Files & NIO.2 —
Path/Files, the stream name clash, and bytes vs characters. - Modern Java Idioms & the Type System — records + sealed + patterns as one data-oriented design.
- Testing, Tooling & Packaging — JUnit 5, build tools, dependencies, and executable JARs.
- Localization —
Locale,NumberFormat, localized dates, resource bundles, andMessageFormat.
Every code block with a ▶ Run button is live. Where behavior is nondeterministic or project-level, the concurrency, performance and tooling lessons include real captured runs instead (a data race, JIT and GC logs, a mvn test summary). The habit that matters most in this chapter is knowing the cost. Streams, parallelism, immutability and abstractions all come with trade-offs, and senior judgment means choosing among them deliberately.
📘 How to read the Intuition boxes. Each one is built in three moves:
- The mechanism — what the compiler and the JVM are actually doing.
- A concrete bite — a specific, runnable failure (often a real compiler error), shown so the trap is visible.
- The earned rule — the decision heuristic, now justified rather than asserted, plus its cost.