This article summarizes the most important changes in the Java ecosystem from Java 8 to Java 21 for developers returning after a break.
Top 10 Changes Since Java 8
- Records (Java 16) — Immutable data classes in a single line, with automatic constructors,
equals(),hashCode(), andtoString() var(Java 10) — Local type inference; the compiler infers types at compile time (not dynamic like JavaScript)- Text Blocks (Java 15) — Multi-line strings with
"""...""", no more string concatenation or\n - Pattern Matching (Java 16/21) —
instanceofwithout explicit cast;switchwith type patterns and guards - Sealed Classes (Java 17) — Restrict which classes can extend an interface/class; compiler knows all possible subtypes
- Switch Expressions (Java 14) —
switchnow returns a value; arrow syntax (->) andyield - Virtual Threads (Java 21) — Millions of lightweight threads with minimal overhead; Spring Boot 3.2+ supports them with one config line
- Module System (Java 9) — Project Jigsaw; most applications still use the classpath but modules exist
- New Collection Methods —
List.of(),Set.of(),Map.of(),.toList(),getFirst()/getLast() - Built-in HTTP Client (Java 11) —
java.net.http.HttpClientreplaces the oldHttpURLConnection
Key Code Comparison
// Java 8 style: 38-line class
class Benutzer {
private String vorname;
private String nachname;
private int alter;
// constructor, getters, equals, hashCode, toString...
}
// Java 21 style: 1 line
record Benutzer(String vorname, String nachname, int alter) {}
JDK Distribution Landscape
Oracle is no longer the only JDK provider. The recommended distribution is Eclipse Temurin (by the Eclipse Foundation / Adoptium) — free, TCK-tested, and backed by IBM, Red Hat, and Microsoft. Install and manage multiple Java versions with SDKMAN:
curl -s "https://get.sdkman.io" | bash
sdk install java 21.0.4-tem
Virtual Threads (Java 21)
Virtual threads are the biggest change since lambdas. Where traditional OS threads cost ~1 MB of stack each, virtual threads are cheap enough to spawn millions:
// Spring Boot 3.2+: one line in application.properties
// spring.threads.virtual.enabled=true
// Or manually:
try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
for (int i = 0; i < 1_000_000; i++) {
executor.submit(() -> { /* I/O work */ });
}
}
Ecosystem Quick Reference
| Area | Java 8 Era | Today |
|---|---|---|
| Web Framework | Spring MVC | Spring Boot 3.x (requires Java 17+) |
| Namespace | javax.* |
jakarta.* (Jakarta EE) |
| Testing | JUnit 4 | JUnit 5 |
| GC | CMS / Parallel | G1 (default), ZGC, Shenandoah |
| HTTP Client | HttpURLConnection |
java.net.http.HttpClient |
| Data classes | 38-line POJOs | record in one line |
Recommended Stack for New Projects
- JDK: Eclipse Temurin 21
- Build: Maven or Gradle
- Framework: Spring Boot 3.x
- IDE: IntelliJ IDEA Community Edition
- Testing: JUnit 5
Kommentare
Kommentare werden von Remark42 bereitgestellt. Beim Laden werden Daten an unseren Kommentar-Server übertragen.