This project provides a set of runnable Java code examples illustrating new language features and APIs that have been introduced in Java since JDK 11, up to and including JDK 17, the next Long Term Support (LTS) release, which is scheduled to become generally available in Sept 2021.
The project showcases examples of language features that were finalised in JDK releases 12 to JDK 17 inclusive. These are summarised below, categorised by JDK release, along with a link to their final Java Enhancement Proposal (JEP).
1) Language Features Finalised in JDK 14 (March 2020) -
-
Switch Expressions - See JEP 361: Switch Expressions.
2) Language Features Finalised in JDK 15 (Sept 2020) -
-
Text Blocks - See JEP 378: Text Blocks.
3) Language Features Finalised in JDK 16 (March 2021) -
-
Pattern Matching for instanceof - See JEP 394: Pattern Matching for instanceof.
-
Records - See JEP 395: Records.
4) Language Features Finalised in JDK 17 (Sept 2021) -
-
Sealed Classes - See JEP 409: Sealed Classes.
For a full list of the JEPs that were added since the previous JDK 11 LTS release, see https://openjdk.java.net/projects/jdk/17/jeps-since-jdk-11.
The examples are implemented as a set of easy to run tests, using JUnit (5). The source code for the examples can be found in the src/test/java folder.
An explanation of the showcased language features, along with guidance on their usage, can be found in the Javadoc of each of the code examples. (See the commands for generating Javadoc below).
You will need to install a Java 17 JDK. (Use of sdkman is recommended).
Support is provided for building and running the project using either Gradle or Maven as described in the sections below.
The minimum required version of Gradle will be installed if you execute the build using the supplied Gradle wrapper script (./gradlew).
To compile and run all the example tests, enter the following command in the project’s root folder:
./gradlew clean test
To generate the Javadoc, use the following command:
./gradlew clean javadocTests
The generated Javadoc can be found in the standard location for a Gradle project - build/docs/javadoc/index.html.
For more details of Gradle build support see build.gradle in the project’s root folder.
The minimum required version of Maven will be installed if you execute the build using the supplied Maven wrapper script (./mvnw).
To compile and run all the example tests, enter the following command in the project’s root folder:
./mvnw clean test
To generate the Javadoc, use the following command:
./mvnw javadoc:test-javadoc
The generated Javadoc can be found in the standard location for a Maven project - target/site/testapidocs/index.html.
For more details of Maven build support see pom.xml in the project’s root folder.
You can find similar code examples for the new features introduced in earlier versions in Java in my other code repos, including -
-
Java 11 - See GitHub project neiljbrown/java11-examples
-
Java 10 - See GitHub project neiljbrown/java10-examples
-
Java 9 - See GitHub project neiljbrown/java9-examples
-
Java 7 and 8 - See my Bitbucket projects
End.