JDK 13: Dynamic CDS, ZGC Uncommit, Socket API, Switch Expressions, Text Blocks

JDK 13 introduces five notable enhancements—Dynamic CDS Archives for faster startup and lower memory use, ZGC’s ability to uncommit unused heap memory, a modernized socket API replacing legacy classes, preview switch expressions with both statement and expression forms, and preview text blocks for cleaner multi‑line strings.

Programmer DD
Programmer DD
Programmer DD
JDK 13: Dynamic CDS, ZGC Uncommit, Socket API, Switch Expressions, Text Blocks

JDK 13: 5 New Features

JDK 13 adds five major enhancements: Dynamic CDS Archives, ZGC uncommit, reimplemented legacy socket API, switch expressions (preview), and text blocks (preview).

350: Dynamic CDS Archives

Dynamic CDS builds on JEP 310 (Application Class‑Data Sharing) to allow application classes to be placed in shared archive files, reducing memory usage and improving startup time. Goals include sharing class metadata across JVM processes, improving startup, allowing archived classes in custom class loaders, and loading from the JDK runtime image.

Share common class metadata between Java processes to reduce memory.

Improve startup time.

Extend CDS to allow archived classes in custom class loaders.

Allow archived classes from $JAVA_HOME/lib/modules.

Success criteria: significant memory savings across multiple JVMs and noticeable startup time improvement.

JEP 350 enables dynamic class archiving after application execution, including classes not present in the base CDS archive. It removes the need for a separate class‑list step; the -Xshare:dump option can create a static archive.

Previously, using CDS required three steps: run the application to generate a class list, dump an archive using that list, and run with the archive.

Example:

# JVM exits and creates shared archive file
bin/java -XX:ArchiveClassesAtExit=hello.jsa -cp hello.jar Hello
# Run application using the dynamically created archive
bin/java -XX:SharedArchiveFile=hello.jsa -cp hello.jar Hello

351: ZGC Uncommit Unused Memory

ZGC now can return unused heap memory to the operating system, which is important for container environments, idle applications, and workloads with highly variable memory needs. Existing G1 and Shenandoah already provide this capability.

ZGC heap consists of regions called ZPages. When a ZPage is freed, it moves to a ZPageCache, representing unused memory that should be returned to the OS. A simple eviction strategy based on timeout can be used; Shenandoah uses a 5‑minute default, configurable via -XX:ShenandoahUncommitDelay. Future JDK 13 may add more sophisticated heuristics, configurable via -XX:ZUncommitDelay. Uncommit is enabled by default but cannot reduce heap below Xms; setting Xmx equal to Xms disables it, and -XX:-ZUncommit can turn it off.

353: Reimplement the Legacy Socket API

The old java.net.Socket and java.net.ServerSocket implementations are replaced with a new NioSocketImpl based on Java NIO, eliminating native code and thread‑stack IO buffers. Benefits:

Easier maintenance and debugging.

Uses JDK NIO implementation without custom native code.

Leverages buffer cache, removing the need for thread‑stack IO buffers.

Replaces synchronized methods with JUC locks.

354: Switch Expressions (Preview)

Switch expressions can be used as statements or expressions, with traditional case labels or the new arrow syntax, and support pattern matching (JEP 305). Example:

if (obj instanceof String s && s.length() > 5) {
    // ...
}

Preview switch expression usage:

switch (day) {
    case MONDAY, FRIDAY, SUNDAY -> System.out.println(6);
    case TUESDAY -> System.out.println(7);
    case THURSDAY, SATURDAY -> System.out.println(8);
    case WEDNESDAY -> System.out.println(9);
}
int numLetters = switch (day) {
    case MONDAY, FRIDAY, SUNDAY -> 6;
    case TUESDAY -> 7;
    case THURSDAY, SATURDAY -> 8;
    case WEDNESDAY -> 9;
};

355: Text Blocks (Preview)

Text blocks provide multi‑line string literals without needing escape characters, improving readability for embedded XML, JSON, SQL, etc. They replace the deprecated raw‑string syntax (backticks) from JEP 326. Example using text blocks:

String html = """
    <html>
        <body>
            <p>Hello World.</p>
        </body>
    </html>
    """;

Benefits: simplify multi‑line strings and enhance readability.

Reference link: https://openjdk.java.net/projects/jdk/13/
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavazgcJDK13SwitchExpressionsTextBlocksSocketAPIDynamicCDS
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.