Design Patterns Update to JDK25

Author: Miro Wengner

Original post on Foojay: Read More

Table of Contents

The information technology landscape is changing rapidly. This is not only due to the utilization of AI and new methodologies [8], or business requirements trying to keep up, but also because of the incremental complexity of expected solutions.

Statistics and probability are slowly beginning to play a very important role in this evolution. The Java ecosystem has proven its maturity many times by delivering essential features that businesses require, although many may argue that these have been inspired by other existing solutions.

From this perspective, JDK 25’s release can be viewed as an exemplary breakthrough that delivers essential features through multiple ongoing internal projects like:

  1. Babylon, Loom
    a. Babylon [1] aims to extend better support for external programming languages like SQL, machine learning, GPU utilization
    b. Loom [2] aims provide better approach of handling concurrency through Virtual Thread, Scoped Values or Structured Concurrency framework
  2. Leyden, Lilliput
    a. Leayden [3] aims to optimize Java platform startup time and memory footprint using Ahead-of-Time (AOT) techniques to reduce Just-In-Time (JIT) compilation
    b. Lilliput [4] explores possibilities of downsizing the Java object headers from 128 bits to 64 bits or less (HotSpot JVM). Such footprint reduction aims to improve performance across the workloads.
  3. Panama, Valhalla
    a. Panama [5] aims to optimize interoperability between Java and native code through Vector API or Foreign Function and Memory (FFM) API with goal enabling more efficient applications
    b. Valhalla [6] aims to optimize value types to increase Java platform performance through allowing better handling of null types

Java 25 represents a notable milestone, empowering developers to leverage enhanced switch statements to effectively address implementation challenges across Creational, Structural, and Behavioral design patterns.

This release demonstrates a dramatic shift toward functional programming approaches for solving complex challenges (maintainable and testable codebase, security). Code readability has become increasingly self-explanatory, clearly conveying the underlying purpose of the implementation.

Although JDK 25 may be perceived as a release that simplifies the execution of the main() method and related classes without compilation requirements, its impact extends far beyond these surface-level improvements due to the comprehensive collection of included JEPs (see JEPs LTS journey bellow).

public interface Vehicle {
    void move();
    default void printStatus(){
        checkMoving();
    }
    private void checkMoving(){
        System.out.println("checking status");
    }
}

void main(){
    var vehicle1 = new CommonVehicle("super_engine");
    var vehicle2 = new OtherVehicle(42);
    var vehicle3 = new UnknownVehicle();
    List<Vehicle> vehicles = Arrays.asList(vehicle1, vehicle2, vehicle3);

    vehicles.forEach(v -> {
        switch (v){
            case OtherVehicle(Integer horsePowers) -> System.out.println("OtherVehicle with horsePowers:" + horsePowers);
            case CommonVehicle(String engine) -> System.out.println("CommonVehicle with engine:"+ engine);
            default -> System.out.println("not implemented, v:" + v);
        }
    });
}

I have updated the source code for my book “Practical Design Patterns for Java Developers [7]” to JDK 25, maintaining these examples in a separate branch to ensure the code samples referenced in the book remain accessible.

JEPs LTS journey (focus on coding but not only):

note: Stream API, Lambda Expressions, and Java Platform Module System are considered to be previous milestones

JDK17 LTS:
JEP-409: Sealed Classes
JEP-415: Context-Specific Deserialization Filters
JEP-390: Warnings for Value-Based Classes
JEP-394: Pattern Matching for instancesof (since JDK16)
JEP-371: Hidden Classes (since JDK15)
JEP-378: Text Blocks (since JDK15)
JEP-349: JFR Event Streaming (since JDK14)
JEP-352: Non-Volatile Mapped Byte Buffers (since JDK14)
JEP-358: Helpful NullPointerExceptions (since JDK14)
JEP-361: Switch Extension (since JDK14)

JDK21 LTS:
JEP-431: Sequenced Collection
JEP-440: Record Patterns
JEP-441: Pattern Matching for switch
JEP-444: Virtual Threads
JEP-400: UTF-8 Default (since JDK18)
JEP-408: Simple Web Server (since JDK18)
JEP-418: Internet-Address Resolution SPI (since JDK18)

JDK25 LTS:
JEP-485: Stream Gatherers (since JDK24)
JEP-456: Unnamed Variables & Patterns (since JDK22)
JEP-512: Compact Source Files and Instance Main Methods
JEP-458: Launch Multi-File Source Code Programs (since JDK22)
JEP-518: JFR Cooperative Sampling
JEP-520: JFR Method Timing & Tracing

References:

  1. Project Babylon
  2. Project Loom
  3. Project Leyden
  4. Project Lilliput
  5. Project Panama
  6. Project Valhalla
  7. GitHub Update to JDK25, Practical Design Patterns for Java Developers
  8. Stochastic AI Agility

The post Design Patterns Update to JDK25 appeared first on foojay.