Java has evolved. Your code can too.
A collection of 85 side-by-side code comparisons showing old Java patterns next to their clean, modern replacements — from Java 8 all the way to Java 25.
Every snippet shows two panels:
- ✕ Old — the traditional way (Java 7/8 era)
- ✓ Modern — the clean, idiomatic replacement (Java 9–25)
Each comparison includes an explanation of why the modern approach is better, which JDK version introduced it, and links to related patterns.
| Category | Examples |
|---|---|
| Language | Records, sealed classes, pattern matching, switch expressions, var, unnamed variables |
| Collections | Immutable factories, sequenced collections, unmodifiable collectors |
| Strings | Text blocks, isBlank(), strip(), repeat(), formatted(), indent() |
| Streams | toList(), mapMulti(), takeWhile()/dropWhile(), gatherers |
| Concurrency | Virtual threads, structured concurrency, scoped values, ExecutorService as AutoCloseable |
| I/O | Files.readString(), writeString(), Path.of(), transferTo(), HTTP Client |
| Errors | requireNonNullElse(), record-based errors, deserialization filters |
| Date/Time | java.time basics, Duration/Period, DateTimeFormatter, instant precision |
| Security | TLS defaults, SecureRandom, PEM encoding, key derivation functions |
| Tooling | JShell, single-file execution, JFR profiling, compact source files, AOT |
This site uses a JSON-first build pipeline:
- Source of truth: Individual
category/slug.jsonfiles (85 across 10 category folders) - Template:
slug-template.html— shared HTML template with{{placeholder}}tokens - Generator:
generate.java— a JBang script that produces all HTML detail pages anddata/snippets.json - Deploy: GitHub Actions runs the generator and deploys to GitHub Pages
Generated files (category/*.html and data/snippets.json) are in .gitignore — never edit them directly.
- Java 25+ (e.g. Temurin)
- JBang (
brew install jbang/sdk install jbang/ other options)
# Generate all HTML pages and data/snippets.json into site/
jbang generate.java
# Serve locally
python3 -m http.server -d site 8090
# Open http://localhost:8090The generator is a compact source file (Java 25) that uses Jackson for JSON parsing. On first run, JBang resolves the Jackson dependency (~2s); subsequent runs use a cached jar (~0.8s).
A Python equivalent (generate.py) is also available and produces identical output:
python3 generate.pyContributions are welcome! Content is managed as JSON files — never edit generated HTML.
- Fork the repo
- Create or edit a JSON file in the appropriate content folder (e.g.
content/language/my-feature.json) - Follow the snippet JSON schema for all required fields
- Run
jbang generate.javato verify your changes build correctly - Update
site/index.htmlwith a new preview card if adding a new snippet - Open a pull request
Please ensure JDK version labels only reference the version where a feature became final (non-preview).
- Plain HTML, CSS, and JavaScript — no frontend frameworks
- JBang + Jackson for build-time generation
- Hosted on GitHub Pages via GitHub Actions
Bruno Borges
- GitHub: @brunoborges
- X/Twitter: @brunoborges
- LinkedIn: brunocborges
This project is licensed under the MIT License.