Skip to content

Latest commit

 

History

History
65 lines (45 loc) · 3.75 KB

File metadata and controls

65 lines (45 loc) · 3.75 KB
title Overview of New Features in Java 17 (Important)
category Java
tag
New Features in Java

Java 17 was officially released on September 14, 2021, and is a Long-Term Support (LTS) version.

The following image shows the timeline for Oracle JDK support provided by Oracle. As can be seen, Java 17 will be supported until September 2029 at the latest.

Java 17 will be the most important Long-Term Support (LTS) version since Java 8, representing eight years of effort from the Java community. Spring 6.x and Spring Boot 3.x require at least Java 17.

This update brings a total of 14 new features:

Here, I will provide a detailed introduction to the new features I consider important: 356, 398, 406, 407, 409, 410, 411, 412, and 414.

Related reading: OpenJDK Java 17 Documentation .

JEP 356: Enhanced Pseudo-Random Number Generators

Before JDK 17, we could generate random numbers using Random, ThreadLocalRandom, and SplittableRandom. However, these three classes each have their drawbacks and lack support for common pseudo-random algorithms.

Java 17 introduces new interface types and implementations for pseudo-random number generators (PRNGs), making it easier for developers to interchange various PRNG algorithms in their applications.

PRNG is used to generate sequences of numbers that are close to absolute randomness. Generally, a PRNG relies on an initial value, also known as a seed, to generate the corresponding pseudo-random number sequence. As long as the seed is determined, the random numbers generated by the PRNG are completely predictable, so the generated sequence is not truly random.

Example of usage:

RandomGeneratorFactory<RandomGenerator> l128X256MixRandom = RandomGeneratorFactory.of("L128X256MixRandom");
// Use the current timestamp as the random seed
RandomGenerator randomGenerator = l128X256MixRandom.create(System.currentTimeMillis());
// Generate a random number
randomGenerator.nextInt(10);

JEP 398: Deprecate the Applet API for Removal

The Applet API was used to write Java applets that run on the web browser side, and it has been obsolete for many years, with no reason to use it anymore.

The Applet API was marked as deprecated in Java 9 (JEP 289), but not for removal.

JEP 406: Pattern Matching for switch (Preview)

Just like instanceof, switch has also added automatic type matching functionality.

Example of `instance