What’s New in Java 13? 5 Game‑Changing Features Explained
This article outlines Java 13’s release schedule, its five major JEPs—including Dynamic CDS Archives, ZGC memory uncommit, a revamped Socket API, Switch Expressions, and Text Blocks—detailing how each feature works, its usage steps, and sample code to help developers adopt them.
In August 2017 the JCP Executive Committee announced a six‑month release cadence for Java, with releases in March and September each year. JDK 13 was scheduled for September 17 2019 and is available for download at jdk.java.net/13 , with beta builds for Linux, macOS, and Windows.
JDK 13 entered the Release‑Candidate phase and includes five fixed features:
JEP 350 Dynamic CDS Archives, JEP 351 ZGC: Uncommit Unused Memory, JEP 353 Reimplement the Legacy Socket API, JEP 354 Switch Expressions (Preview), JEP 355 Text Blocks (Preview)
Dynamic CDS Archives
Building on JEP 310 (Application Class‑Data Sharing), Dynamic CDS Archives allow classes loaded at runtime to be archived dynamically after the application exits. This extends the original CDS, which only shared classes loaded by the boot class loader, to also include classes loaded by the application class loader (AppCDS). The process previously required three steps:
1. Decide which classes to dump
2. Dump the class memory to an archive file
3. Use the archive to speed up subsequent startsJEP 350 simplifies this by automatically archiving all loaded application and library classes that are not already in the base CDS archive, eliminating the manual steps.
ZGC: Uncommit Unused Memory
Earlier, ZGC (introduced experimentally in JDK 11) did not return freed heap memory to the operating system. JEP 351 enhances ZGC so that unused heap memory can be returned, which is valuable in containerized environments, workloads with variable memory demands, or when applications spend long periods idle.
Pay‑per‑use containers
Environments where applications share or compete for resources
Applications with highly variable heap size requirements
Reimplement the Legacy Socket API
JEP 353 provides a modern implementation of java.net.Socket and java.net.ServerSocket, replacing the old, hard‑to‑maintain code. The new implementation is the default in Java 13, but the legacy version can still be used by setting the system property jdk.net.usePlainSocketImpl. Example output of class loading with the new implementation:
java -XX:+TraceClassLoading JEP353 | grep Socket
[0.033s][info ][class,load] java.net.Socket source: jrt:/java.base
[0.035s][info ][class,load] java.net.SocketOptions source: jrt:/java.base
[0.042s][info ][class,load] sun.net.PlatformSocketImpl source: jrt:/java.base
[0.044s][info ][class,load] java.net.ServerSocket source: jrt:/java.baseUsing the legacy implementation:
java -Djdk.net.usePlainSocketImpl -XX:+TraceClassLoading JEP353 | grep Socket
[0.037s][info ][class,load] java.net.Socket source: jrt:/java.base
[0.047s][info ][class,load] java.net.PlainSocketImpl source: jrt:/java.baseSwitch Expressions (Preview)
Introduced as a preview in JDK 12, JEP 354 adds the yield statement to return a value from a switch expression, distinguishing it from return which exits the method. Traditional switch statements required verbose code; with the new syntax:
int i = switch (x) {
case "1" -> 1;
case "2" -> 2;
default -> {
int len = args[1].length();
yield len;
}
};Text Blocks (Preview)
JEP 355 replaces the abandoned Raw String Literals with Text Blocks, allowing multi‑line string literals without most escape sequences. A text block is delimited by triple quotes ( """) and preserves formatting, making embedded HTML or SQL much clearer:
String html = """
<html>
<body>
<p>Hello, world</p>
</body>
</html>
""";These two preview features (Switch Expressions and Text Blocks) can significantly improve code readability, though they remain non‑standard until a future release.
Conclusion
The five JDK 13 features that most affect developers are Dynamic CDS Archives, ZGC memory uncommit, the new Socket API, Switch Expressions, and Text Blocks. While the latter two are still preview features, they already offer clearer, more concise code. Note that JDK 13 is not an LTS release; users on Java 8 or Java 11 (both LTS) may choose to stay on those versions.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
