DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

  1. DZone
  2. Refcards
  3. Java 13
refcard cover
Refcard #318

Java 13

A Java expert goes over everything Java developers need to know about the new JDK 13, walking through code examples to illustrate these new updates and the benefits they bring.

Download Refcard
Free PDF for Easy Reference
refcard cover

Written By

author avatar Simon Ritter
Deputy CTO, Azul Systems
Table of Contents
► Introduction ► Text Blocks ► Switch Expressions ► New JEPs ► New APIs ► Conclusion
Section 1

Introduction

We are now well into the new six-month release cadence of the JDK and, with the release of JDK 13, it is clearly working well.

One thing that is obvious is that, whilst the overall rate of change for the Java platform has increased, individual releases will have fewer new features. This is the case with JDK 13, which includes only five JDK Enhancement Proposals (JEPs) and 76 new core library elements (of which nearly half are simple additions to the java.io package).


This is a preview of the Java 13 Refcard. To read the entire Refcard, please download the PDF from the link above.

Section 2

Text Blocks

Let's start with a change to the language syntax, in the form of text blocks (JEP 355). Java has always suffered a little from the way strings are defined. A string starts with a double-quote and ends with a double-quote, which is fine, except that the string cannot span more than one line. This leads to workarounds, like including \n where line breaks are required or concatenating strings and newlines, but these do not lend themselves to clear code. In JDK 12, there was a proposal for raw-string literals (JEP 326), but the feedback from the early access builds of the JDK was such that the decision was made to remove it before release.

Text blocks are a different solution to the same challenge. A text block starts with a triple double-quote and is terminated with the same. Anything between them is interpreted as a part of the string, including new lines. There is nothing magical about the end result, which is still a normal java.lang.String object. Text blocks can be used anywhere that a string literal can be used in Java with no difference to the compiled code.


This is a preview of the Java 13 Refcard. To read the entire Refcard, please download the PDF from the link above.

Section 3

Switch Expressions

There is another (small) language change in JDK 13, covered by JEP 354. This applies to the switch expression feature that was included in JDK 12 as the first-ever preview feature. Here, we have a perfect example of why preview features are an excellent idea.

Until JDK 12, a switch could only be used as a statement, where it performed an action but did not return a result. In JDK 12, a switch can now be used as an expression, meaning it returns a result that can be assigned to a variable. There were also several changes to the syntax of case statements within the switch expressions. Let's use the example from the JEP to understand how this works.


This is a preview of the Java 13 Refcard. To read the entire Refcard, please download the PDF from the link above.

Section 4

New JEPs

JDK 13 also includes three JEPs that relate to the virtual machine.

  • JEP 350: Dynamic CDS Archive. This is an extension to the application class data sharing functionality (AppCDS) that was contributed by Oracle to OpenJDK 10. Prior to that, it was included in the Oracle JDK as a commercial feature. This extension allows the dynamic archiving of classes at the end of the execution of a Java application. The archived classes include all loaded application classes and library classes that are not present in the default, base-layer CDS archive. This also eliminates the need to perform a training run of an application. Using AppCDS prior to this was a multi-step process involving the creation of a list of relevant classes and using this list to generate the archive to be used for subsequent runs. Now, all that is required is a single run of an application with the -XX:ArchiveClassesAtExit flag providing the location where the archive will be written.

This is a preview of the Java 13 Refcard. To read the entire Refcard, please download the PDF from the link above

Section 5

New APIs

As mentioned previously, JDK 13 includes only 76 new APIs in the core class libraries. These cover the following areas:

  • Updates to Unicode support.
  • Three new methods in String to support text blocks already described.
  • The type-specific Buffer classes of java.nio now have absolute (as opposed to relative) bulk get and set methods. They, as well as the base abstract Buffer class, include a slice() method to extract part of the buffer.
  • MappedByteBuffer has a force() method that will force a write of a section of the buffer to its backing store.
  • java.nio.FileSystem adds three new overloaded forms of  newFileSystem() to access the contents of a file as a file system.
  • There's an interesting new method in  javax.annotation.processing.ProcessingEnvironment --- isPreviewEnabled(). This will tell you whether the preview features (discussed earlier) are enabled. The reason this is interesting is that the annotation, @PreviewFeature, will not be available until JDK 14.
  • Element-specific types in javax.lang.model.element all get the asType() method. This returns a pseudo-type.
  •  DocumentBuilderFactory and  SAXParserFactory in  javax.xml.parsers get three new methods to create namespace-aware instances.

This is a preview of the Java 13 Refcard. To read the entire Refcard, please download the PDF from the link above

Section 6

Conclusion

As you can see, JDK 13 does not have a large number of new features and APIs. However, it continues to deliver the incremental evolution of Java, ensuring it remains the most popular programming language on the planet.


This is a preview of the Java 13 Refcard. To read the entire Refcard, please download the PDF from the link above.

Like This Refcard? Read More From DZone

related article thumbnail

DZone Article

Guide for Supporting Multiple Versions of Java (8, 11, 14) in Your Maven Project
related article thumbnail

DZone Article

Bridging UI, DevOps, and AI: A Full-Stack Engineer’s Approach to Resilient Systems
related article thumbnail

DZone Article

The Ultimate Guide to Code Formatting: Prettier vs ESLint vs Biome
related article thumbnail

DZone Article

Security by Design: Building Full-Stack Applications With DevSecOps
related refcard thumbnail

Free DZone Refcard

Java Application Containerization and Deployment
related refcard thumbnail

Free DZone Refcard

Introduction to Cloud-Native Java
related refcard thumbnail

Free DZone Refcard

Java 15
related refcard thumbnail

Free DZone Refcard

Java 14

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: