Java 8 to Java 25 Features

The language and platform changes from Java 8 through Java 25 LTS that matter to architects, with code examples and upgrade guidance.

[!VERSION] LTS releases: 8, 11, 17, 21, 25 (September 2025). Since Java 21 Oracle moved to a two-year LTS cadence. Non-LTS releases ship every March and September; check the JDK release notes for anything after Java 25.

Release highlights

Version Key features for architects
8 (2014, LTS) Lambdas, streams, Optional, java.time, default methods, CompletableFuture
9 Module system (JPMS), JShell, List.of/Map.of, HTTP/2 client (incubator)
10 var local type inference, container awareness improvements
11 (LTS) Standard HttpClient, String helpers, single-file launch, ZGC (experimental), Flight Recorder open-sourced
14 Switch expressions, helpful NullPointerExceptions
15 Text blocks, ZGC and Shenandoah production-ready
16 Records, pattern matching for instanceof, strong encapsulation of JDK internals
17 (LTS) Sealed classes, new macOS rendering, removal of RMI activation
21 (LTS) Virtual threads, record patterns, pattern matching for switch, sequenced collections, generational ZGC
22 Unnamed variables and patterns (_), Foreign Function & Memory API final, launch multi-file source programs
23 Markdown documentation comments, generational mode default for ZGC
24 Stream gatherers final, Class-File API final, virtual threads synchronize without pinning (JEP 491), ahead-of-time class loading and linking, quantum-resistant ML-KEM and ML-DSA, non-generational ZGC removed
25 (LTS) Scoped values final, module import declarations, compact source files and instance main methods, flexible constructor bodies, compact object headers (product feature), generational Shenandoah, AOT method profiling, key derivation function API; structured concurrency still in preview

Code examples

Records, sealed types and pattern matching (17–21)

sealed interface PaymentResult permits Approved, Declined, Pending {}
record Approved(String authCode) implements PaymentResult {}
record Declined(String reason) implements PaymentResult {}
record Pending(String checkUrl) implements PaymentResult {}

String describe(PaymentResult r) {
    return switch (r) {                      // exhaustive: compiler checks all permitted types
        case Approved(var code) -> "Approved " + code;
        case Declined(var reason) when reason.startsWith("FRAUD") -> "Blocked";
        case Declined(var reason) -> "Declined: " + reason;
        case Pending p -> "Check status at " + p.checkUrl();
    };
}

Sequenced collections (21)

SequencedCollection<String> steps = new ArrayList<>(List.of("validate", "reserve", "charge"));
steps.getFirst(); steps.getLast(); steps.reversed();

Stream gatherers (24)

// Sliding windows of 3 readings to compute moving averages
List<Double> averages = readings.stream()
    .gather(Gatherers.windowSliding(3))
    .map(w -> w.stream().mapToDouble(Double::doubleValue).average().orElse(0))
    .toList();

Scoped values (final in 25)

static final ScopedValue<String> REQUEST_ID = ScopedValue.newInstance();
ScopedValue.where(REQUEST_ID, "req-42").run(() -> handle());   // immutable, inherited by child tasks

Compact source files and instance main (25)

void main() {
    IO.println("Hello from a compact source file");
}

Upgrade guidance

  • Move from 8/11 to 21 or 25: big gains in GC, startup, container awareness and developer productivity; virtual threads alone can simplify concurrency.
  • Watch for removed internals (--illegal-access gone since 17), deprecated APIs (Security Manager permanently disabled in 24), library compatibility (Spring Boot 3 requires Java 17+).
  • Use jdeprscan and jdeps to find usage of removed or internal APIs; upgrade build tools and frameworks first.

[!ARCHITECT] Standardize the organization on the current or previous LTS, with a policy to adopt each new LTS within ~12 months. Running 8 in 2026 means missing security improvements and paying for extended support.

Interview questions and answers

Why should a team move from Java 17 to 21 or 25?

Virtual threads for high-concurrency I/O, pattern matching that simplifies domain code, generational ZGC for low-latency large heaps, and in 24–25 the removal of virtual-thread pinning with synchronized, compact object headers that reduce memory, and AOT startup improvements.

What are records good for, and what are they not?

Immutable data carriers: DTOs, value objects, events, query results. Not JPA entities (entities need mutability and no-arg constructors) and not types with hidden mutable state.