Key New Features in JDK 13: Dynamic CDS Archives, ZGC, Reimplemented Socket API, Switch Expressions, and Text Blocks
This article explains the five major JDK 13 enhancements—Dynamic CDS Archives, ZGC memory uncommit, a modern Socket API, preview Switch Expressions, and Text Blocks—detailing their purpose, usage, and code examples while noting that JDK 13 is not a long‑term support release.
In August 2017 the JCP Executive Committee announced a six‑month release cadence for Java, with new versions scheduled for March and September each year; JDK 13 was slated for release on 17 September 2019.
At the time of writing JDK 13 was in the Release‑Candidate phase and its feature set was frozen, comprising five notable JEPs:
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)
1. Dynamic CDS Archives extends the original Class‑Data Sharing (CDS) introduced in JEP 310. CDS allows classes loaded by the boot class loader to be shared across JVM instances, reducing startup time and memory usage. Java 10 expanded CDS to AppCDS, which also covers classes loaded by the application class loader, further widening the sharing scope.
Using AppCDS traditionally required three steps: (1) decide which classes to dump, (2) dump their memory into an archive file, and (3) use that archive to accelerate subsequent application starts. JDK 13’s JEP 350 automates this by dynamically archiving all loaded application and library classes at JVM shutdown, eliminating the manual process.
2. ZGC: Uncommit Unused Memory builds on the experimental Z Garbage Collector introduced in JDK 11. Earlier versions of ZGC did not return freed heap memory to the operating system. JEP 351 enhances ZGC so that unused heap pages are returned, which is valuable in containerized environments, idle workloads, or applications with highly variable memory demands.
3. Reimplement the Legacy Socket API replaces the old java.net.Socket and java.net.ServerSocket implementations with a modern, easier‑to‑maintain version. The new implementation is the default in JDK 13, but the legacy version can still be used by setting the system property jdk.net.usePlainSocketImpl. Example output of class‑loading traces shows the new sun.nio.ch.NioSocketImpl in action:
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.039s][info] class,load java.net.SocketImpl source: jrt:/java.base
[0.042s][info] class,load sun.net.PlatformSocketImpl source: jrt:/java.base
[0.045s][info] class,load java.net.ServerSocket source: jrt:/java.baseRunning the same command with -Djdk.net.usePlainSocketImpl demonstrates the legacy java.net.PlainSocketImpl being used.
4. Switch Expressions (Preview) were introduced as a preview feature in JDK 12 (JEP 354) and refined in JDK 13. Switch expressions now support the yield keyword to return a value from the switch block, distinguishing them from traditional switch statements that use break. Example:
int i = switch (x) {
case "1" -> 1;
case "2" -> 2;
default -> {
int len = args[1].length();
yield len;
}
};5. Text Blocks (Preview) replace cumbersome string concatenation and escaping with multi‑line string literals delimited by triple quotes ( """). This allows developers to embed raw text such as HTML or SQL directly in code without manual escaping. Example of an HTML snippet:
String html = """
<html>
<body>
<p>Hello, Hollis</p>
</body>
</html>
""";And a formatted SQL query:
String query = """
SELECT `EMP_ID`, `LAST_NAME`
FROM `EMPLOYEE_TB`
WHERE `CITY` = 'INDIANAPOLIS'
ORDER BY `EMP_ID`, `LAST_NAME`;
""";In summary, JDK 13 introduces five significant features that can change developers' coding style, especially the preview Switch Expressions and Text Blocks. However, because JDK 13 is not a long‑term support (LTS) release, users of 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.
Full-Stack Internet Architecture
Introducing full-stack Internet architecture technologies centered on Java
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.
