Overview of New Features in Java 13

Introduction Java 13 was released on 17th September 2019. With five JDK Enhancement Proposals (JEPs), it was one of the smallest releases since Java moved to a six-month release cadence - a good example of the new model, in which a release simply ships whatever is ready. Its most visible changes are previews of two language features which later became standard. This article gives an overview of the new features in Java 13, with links to detailed tutorials. Language features (previews)
  1. Text Blocks (Preview) - JEP 355 - multi-line string literals delimited by three double quotes ("""), which make embedded JSON, SQL and HTML readable, with no \n escapes or + concatenation. Text blocks replaced the withdrawn raw string literals of Java 12, were previewed again in Java 14, and became standard in Java 15. Read the tutorial on text blocksClick to read tutorial: Java Text Blocks: Multi-line Strings with Examples.
  2. Switch Expressions (Second Preview) - JEP 354 - the switch expressions previewed in Java 12, with one change based on feedback: a value is returned from a block in a switch expression with the new yield statement instead of break value;. They became standard in Java 14. Read the tutorial on switch expressions and yieldClick to read tutorial: Java Switch Expressions: Arrow Labels and yield.
JVM and library features
  1. Dynamic CDS Archives - JEP 350 - creating an application class-data sharing archive used to take two extra steps: dumping a list of the loaded classes, and then building the archive. Now, running the application once with -XX:ArchiveClassesAtExit=app.jsa creates the archive automatically when the application exits, and later runs use it with -XX:SharedArchiveFile=app.jsa for a faster startup. See the AppCDS tutorialClick to read: AppCDS tutorial for the background.
  2. ZGC: Uncommit Unused Memory - JEP 351 - the ZGC garbage collector can now return unused heap memory to the operating system, as G1 started doing in Java 12. ZGC itself became production-ready in Java 15 - read about ZGC and ShenandoahClick to read tutorial: ZGC and Shenandoah: Low-Pause GCs in Java 15.
  3. Reimplement the Legacy Socket API - JEP 353 - the code behind java.net.Socket and ServerSocket, which dated back to JDK 1.0 and mixed Java and C, was replaced by a simpler, modern implementation (NioSocketImpl). Application code does not change; the new implementation was also prepared to work with the virtual threads which came later in Java 21Click to read: Java 21. The DatagramSocket API followed in Java 15.
Smaller library changes
  • FileSystems.newFileSystem(Path) - opening a ZIP or JAR file as a file system no longer needs a class loader argument.
  • ByteBuffer got absolute bulk get and put methods, which read or write a range of bytes at a given index without changing the buffer's position, and a slice(index, length) method.
  • The XML DocumentBuilderFactory and SAXParserFactory got newDefaultNSInstance() methods, which create namespace-aware parsers directly.
  • Unicode support was upgraded to Unicode 12.1.
Summary In this article we went through the new features of Java 13. On the language side it previewed text blocks, and previewed switch expressions a second time with the new yield statement. On the JVM side, dynamic CDS archives made faster startup a one-flag affair, ZGC learned to give memory back to the operating system, and the old socket implementation was rewritten. Lastly, we listed the smaller library changes. Next, read the overview of new features in Java 14Click to read tutorial: Overview of New Features in Java 14.