| title | Overview of New Features in Java 17 (Important) | |
|---|---|---|
| category | Java | |
| tag |
|
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:
- JEP 306: Restore Always-Strict Floating-Point Semantics
- JEP 356: Enhanced Pseudo-Random Number Generators
- JEP 382: New macOS Rendering Pipeline
- JEP 391: macOS/AArch64 Port
- JEP 398: Deprecate the Applet API for Removal
- JEP 403: Strongly Encapsulate JDK Internals
- JEP 406: Pattern Matching for switch (Preview)
- JEP 407: Remove RMI Activation
- JEP 409: Sealed Classes (Standardized)
- JEP 410: Remove the Experimental AOT and JIT Compiler
- JEP 411: Deprecate the Security Manager for Removal
- JEP 412: Foreign Function & Memory API (Incubating)
- JEP 414: Vector API (Second Incubation)
- JEP 415: Context-Specific Deserialization Filters
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 .
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);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.
Just like instanceof, switch has also added automatic type matching functionality.
Example of `instance
