Java - Overview

Key Concepts of the Java Ecosystem

Java vs JVM

  • Java: A high-level, object-oriented language defined by The Java Language Specification (JLS).
  • JVM (Java Virtual Machine): The execution environment defined by The Java Virtual Machine Specification (JVMS). It interprets or JIT-compiles Java bytecode into native machine instructions.
  • JVM languages beyond Java include Kotlin, Scala, Groovy, and Clojure.
  • HotSpot is the standard reference JVM implementation in OpenJDK.

JDK vs JRE

  • JDK (Java Development Kit): Complete toolkit containing the Java compiler (javac), runtime environment, debugging tools, and standard libraries. Required for development.
  • JRE (Java Runtime Environment - Deprecated): Standalone runtime containing only the JVM and libraries. JRE installers were discontinued in JDK 11; custom minimal runtime images are now created using jlink alongside the Java Platform Module System (JPMS).

OpenJDK vs Oracle JDK

  • OpenJDK: The official free, open-source reference implementation of the Java SE Platform licensed under GPLv2 with Classpath Exception.
  • Oracle JDK: Oracle's commercial build of OpenJDK, provided under the Free Terms and Conditions (FTC) license for personal and development use, and commercial subscription models for enterprise production support.
  • Other popular vendor distributions of OpenJDK include Amazon Corretto, Eclipse Temurin (Adoptium), Microsoft Build of OpenJDK, and Azul Zulu.

Java SE vs Jakarta EE

  • Java SE (Standard Edition): The core platform containing the language, JVM, and core libraries (java.base, java.net, java.util, java.concurrent).
  • Jakarta EE (formerly Java EE / Enterprise Edition): A set of specifications for enterprise computing (Servlets, JPA, JAX-RS, JMS), transferred from Oracle to the Eclipse Foundation and renamed to Jakarta EE (jakarta.* namespace).
  • In Java 11 (JEP 320), legacy EE modules (java.xml.bind, java.xml.ws, java.corba) were removed from Java SE.

Standards & Processes: JCP, JSR, and JEP

  • JCP (Java Community Process): The formal mechanism for developing standard technical specifications for Java technology.
  • JSR (Java Specification Request): The formal proposal document submitted to the JCP describing proposed specification additions or revisions.
  • JEP (JDK Enhancement Proposal): The process used by OpenJDK to propose and review enhancements to the JDK codebase and platform.

Release Cadence & LTS Versions

Java follows a predictable six-month release cadence (March and September):

  • Feature releases occur every 6 months.
  • Long-Term Support (LTS) releases occur every 2 years:
    • Java 25 (September 2025) — Latest LTS release (FFM API, Stream Gatherers, Lilliput Compact Headers, Flexible Constructors)
    • Java 21 (September 2023) — LTS (Virtual Threads, Pattern Matching for switch, Record Patterns)
    • Java 17 (September 2021) — LTS (Records, Sealed Classes, Text Blocks, Switch Expressions)
    • Java 11 (September 2018) — First modular LTS (var inference, HttpClient)
    • Java 8 (March 2014) — Legacy baseline (Lambdas, Streams)

Modern Java LTS Evolution (25, 21, 17, 11)

LTS Comparison Matrix

Version Release Core Language Additions Runtime & Performance Highlights
Java 25 Sep 2025 Foreign Function & Memory API (Panama), Stream Gatherers, Unnamed Variables (_), Flexible Constructor Bodies, Simple Source Files & IO Compact Object Headers (Lilliput) (10-20% heap savings), Generational Shenandoah GC, Leyden AOT optimizations, 32-bit x86 removed
Java 21 Sep 2023 Virtual Threads (Loom), Pattern matching for switch, Record Patterns, Sequenced Collections Generational ZGC (sub-ms pauses), UTF-8 by default across all platforms
Java 17 Sep 2021 Records, Sealed Classes, Text Blocks, Pattern matching for instanceof, Switch expressions Strong encapsulation of internal JDK APIs (--add-opens), macOS AArch64 (Apple Silicon), CMS GC removed
Java 11 Sep 2018 Local variable syntax for lambdas (var), private interface methods, String strip/repeat/lines JPMS modular runtime, G1 made default GC, removal of Applet & Java EE modules, jlink

Java 25 Landmark Additions

  • Foreign Function & Memory API (JEP 454): Standard, type-safe API to call native C libraries and access off-heap memory without JNI boilerplate, native compilation, or security holes:
    Linker linker = Linker.nativeLinker();
    MethodHandle strlen = linker.downcallHandle(
        linker.defaultLookup().find("strlen").orElseThrow(),
        FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.ADDRESS)
    );
    try (Arena arena = Arena.ofConfined()) {
        MemorySegment cString = arena.allocateFrom("Hello, Java 25!");
        long len = (long) strlen.invoke(cString);
    }
    
  • Stream Gatherers (JEP 485): Enhances the Stream API with customizable intermediate operations (windowing, folding, chunking) that previously required custom collectors or third-party libraries:
    // Chunk stream elements into fixed-size batches
    List<List<Integer>> batches = Stream.iterate(0, i -> i + 1)
        .limit(10)
        .gather(Gatherers.windowFixed(3))
        .toList(); // [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]]
    
  • Unnamed Variables & Patterns (_, JEP 456): Cleaner code by marking unused variables and patterns with an underscore:
    // Unused exception variable
    try { parse(); } catch (NumberFormatException _) { /* ignore */ }
    
    // Unused lambda parameter
    map.forEach((key, _) -> System.out.println(key));
    
    // Unused component in record pattern
    if (record instanceof Point(int x, _)) { ... }
    
  • Flexible Constructor Bodies (JEP 513): Allows executing statements, validations, and argument preprocessing before explicitly invoking super(...) or this(...):
    public class SubClass extends SuperClass {
        public SubClass(int value) {
            if (value < 0) throw new IllegalArgumentException("Negative value");
            var sanitized = sanitize(value);
            super(sanitized); // super call is no longer required to be on line 1!
        }
    }
    
  • Compact Object Headers (Project Lilliput, JEP 519): Reduces 64-bit object header size from 96/128 bits down to 64 bits, yielding automatic 10–20% heap memory savings across enterprise JVM deployments.
  • Compact Source Files & Simple Main (JEP 512): Single-file scripts and entrypoints without boilerplate public class or String[] args:
    import module java.base;
    
    void main() {
        IO.println("Hello from streamlined Java 25!");
    }
    

Java 21 Landmark Additions

  • Virtual Threads (Project Loom): Lightweight threads with negligible memory footprint that enable high-throughput synchronous server applications without reactive framework complexity:
    try (var executor = Executors.newVirtualThreadPerTaskExecutor()) {
        executor.submit(() -> fetchRemoteData());
    }
    
  • Pattern Matching for switch: Matching patterns on types with guard clauses (when):
    String result = switch (obj) {
        case Integer i -> "Integer: " + i;
        case String s when !s.isBlank() -> "Non-empty string: " + s;
        case null -> "Null reference";
        default -> "Other type";
    };
    
  • Record Patterns: Nested deconstruction of records:
    if (shape instanceof Point(int x, int y)) {
        System.out.println("Point coordinates: " + x + ", " + y);
    }
    
  • Sequenced Collections: Standardized access to first/last elements and reversed views:
    List<String> list = new ArrayList<>();
    list.addFirst("start");
    list.addLast("end");
    String first = list.getFirst();
    List<String> reversed = list.reversed();
    
  • Generational ZGC: Ultra-low latency GC with sub-millisecond pauses optimized for multi-terabyte heaps.

Java 17 Landmark Additions

  • Records: Compact, immutable data carriers that auto-generate constructors, accessors, equals(), hashCode(), and toString():
    public record User(long id, String name, String email) {}
    
  • Sealed Classes & Interfaces: Restrict which subclasses or implementations are permitted to extend them:
    public sealed interface Shape permits Circle, Rectangle {}
    public final class Circle implements Shape {}
    public final class Rectangle implements Shape {}
    
  • Text Blocks: Multi-line string literals with automatic indentation stripping:
    String query = """
        SELECT id, name
        FROM users
        WHERE active = true;
        """;
    
  • Switch Expressions: Exhaustive expressions using the arrow syntax (->) and yield:
    int days = switch (month) {
        case FEB -> isLeapYear ? 29 : 28;
        case APR, JUN, SEP, NOV -> 30;
        default -> 31;
    };
    
  • Pattern Matching for instanceof: Eliminates manual casting after type checking:
    if (obj instanceof String s) {
        System.out.println(s.toLowerCase());
    }
    

Java 11 Landmark Additions

  • Local-Variable Type Inference (var): Allows cleaner code without explicit typing for local variables and lambda parameters:
    var list = new ArrayList<String>();
    var map = Map.of("k1", "v1", "k2", "v2");
    
  • Standard HTTP/2 Client (java.net.http.HttpClient): Native reactive HTTP/1.1 and HTTP/2 client supporting async non-blocking operations:
    HttpClient client = HttpClient.newHttpClient();
    HttpRequest request = HttpRequest.newBuilder().uri(URI.create("https://api.example.com")).build();
    HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
    
  • Single-File Source Execution: Run .java files directly without an explicit javac compile step (java Application.java).

Migration Gotchas & Upgrading Pitfalls

  • Migrating to Java 25 (from 21):
    • Removal of 32-bit x86: Older 32-bit x86 JVM builds are permanently discontinued.
    • Strict Memory Safety Checks: Accessing native memory outside of structured Arena lifetimes requires explicit opt-in flags.
  • Migrating to Java 21 (from 17):
    • Security Manager Deprecation: Applications relying on SecurityManager for sandbox security must migrate to containerized or OS-level process isolation.
    • Agent Dynamic Loading Warnings: Attaching dynamic JVMTI / Java agents to running JVMs issues warnings unless -XX:+EnableDynamicAgentLoading is set.
  • Migrating to Java 17 (from 11):
    • Strong Encapsulation of JDK Internals: Deep reflection on internal packages (sun.misc.*, internal JDK classes) fails with InaccessibleObjectException. Fix by upgrading libraries or explicitly opening packages via JVM startup flags:
      --add-opens java.base/java.lang=ALL-UNNAMED
      
    • Removed CMS GC: The Concurrent Mark Sweep collector was completely removed; switch to -XX:+UseG1GC or -XX:+UseZGC.
  • Migrating to Java 11 (from 8):
    • Removed Java EE modules (javax.xml.bind.* / JAXB). Fix by explicitly declaring Jakarta or standalone Maven dependencies.
    • Incompatible build plugins; requires updating Maven compiler plugin and Gradle.

Active OpenJDK Innovation Projects

  • Project Loom: Concurrency abstractions (Virtual Threads, Structured Concurrency, Scoped Values).
  • Project Panama: Foreign Function & Memory API (FFM API) to interconnect JVM code with native libraries without JNI boilerplate.
  • Project Amber: Productivity-oriented Java language syntax enhancements (Pattern Matching, String Templates, Primitive types in patterns).
  • Project Valhalla: Identity-free value objects and specialized generics to improve memory density and CPU cache efficiency.
  • Project Leyden: Ahead-of-Time (AOT) optimizations to drastically reduce JVM warmup time and improve cloud-native startup speeds.
  • GraalVM: High-performance multilingual runtime with Ahead-of-Time (AOT) Native Image compilation for instant startup and low memory footprint in microservices.