JDK 13: The new features coming to Java 13

Official development targets for Java 13 include improvements to garbage collection, application class-data sharing, and text blocks

Java Development Kit (JDK) 13, the next version of standard Java, is now available as a release candidate, with all the new features locked down. One capability proposed for JDK 13 but never added to the official list, the jpackage tool for packaging self-contained Java applications, has missed the cut. It is no longer under consideration for JDK 13.

JDK 13 is due September 17, 2019. A second release candidate is due on August 22. Here are the features now officially slated for JDK 13:

  • The addition of text blocks in a preview phase. A text block is a multi-line string literal that avoids the need for most escape sequences. A text block automatically formats the string in a predictable manner and gives developers control over the format. The project cited a number of goals behind the addition of text blocks to Java. One goal is to simplify the writing of Java programs by making it easy to express strings spanning several lines of source code while avoiding escape sequences in common cases. A second goal is enhancing the readability of strings in programs that denote code written in non-Java languages. A third goal is supporting migration from string literals by stipulating that any new construct can express the same set of strings as a string literal, interpret the same escape sequences, and be manipulated like a string literal. Raw string literals, a feature proposed for JDK 13 but dropped in favor of text blocks, took a different approach to the problem of denoting strings without escaping newlines and quotes. Raw string literals focused on the rawness of strings, but the Java project team now believes that focus was wrong, because while raw string literals could span multiple lines of source code, they involved a costly requirement to support un-escaped delimiters. Raw string literals had been projected for JDK 13 but never officially added to its proposed features list.
  • Reimplementing the legacy socket API, which would involve replacing the underlying implementation used by the   net.Socket  and java.net.ServerSocket APIs with a simpler, more modern implementation that is easy to debug and maintain. The new implementation is intended to be easy to adapt to work with user-mode threads, also known as fibers, which are being explored in Project Loom. The aforementioned legacy APIs date back to JDK 1.0 and comprise a mix of legacy C and Java code described as painful to debug and maintain. The legacy implementation also has other issues: a native data structure to support asynchronous close, causing reliability and porting issues, and concurrency issues requiring an overhaul. 
  • A second preview of switch expressions has been proposed for JDK 13. There had been one in JDK 12, but a change is slated to be made: to yield a value from a switch expression, the break with value statement is to be dropped in favor of a yield statement. The intent is to extend switchso it can be used as either a statement or an expression, so both forms can either use traditional case ... : labels with fall through or new case … -> labels without fall through, with a further new statement for yielding a value from a switch expression. These changes will simplify coding and prepare for pattern matching
  • Enhancing the ZGC (Z Garbage Collector) to return unused memory to the operating system, a proposal cited as integrated into JDK 13. ZGC, which is billed as a scalable, low-latency collector, currently does not return unused memory back to the OS even if the memory has not been used in a long time. This behavior is not optimal for some applications and environments, especially those where memory footprint is a concern, such as containers or environments where an application might be idle for a long time and is sharing or competing for resources with other applications.
  • Extending application class-data sharing (AppCDS) to enable dynamic archiving of classes at the end of application execution. Archived classes would include all loaded application and library classes not present in the default, base-layer CDS archive. This proposal, which is in the targeted stage, is intended to improve the usability of AppCDS and eliminate the need for users to do trial runs to create a class list for each application.

Where to download beta JDK 13 builds

You can download the JDK 13 builds from the jdk.java.net website. The first JDK 13 beta builds are available for Linux, MacOS, and Windows.

This story, "JDK 13: The new features coming to Java 13" was originally published by InfoWorld.