Introduction: JDK 17 was released as scheduled on March 16, 2021. This article introduces what’s new in JDK 17. JDK 17 was released on September 14, 2021 as a General Availability Release. JDK 17 will be the long term support (LMS) release from most vendors. The last LTS release was JDK 11. This article summarizes the new features released in JDK 17.

Release Notes

According to the release plan, JDK 17 will be a long-term support release (LTS release). LTS releases come every 3 years, with the last long term support release being JDK 11 in September 2018.

JDK 17 is an open source reference implementation of version 17 of the Java SE platform, specified by JSR 392 in the Java Community Process (JCP).

Download the installation package

The OpenJDK and Oracle versions are available for download as follows:

  • OpenJDK version: jdk.java.net/16/
  • Oracle version: www.oracle.com/java/techno…

The above version, if personal learning use, there is little difference. But if it’s for commercial use, you need to look carefully at the licensing. The Oracle JDK is licensed under the binary code License, while the OpenJDK is licensed under the GPL V2 license.

For more on the basics of Java, see the book Java Core Programming, which is very detailed.

New features in JDK 17

JEP 406: Switch Pattern Matching (Preview) (JDK-8213076)

specification

Enhances the Java programming language with pattern matching of switch expressions and statements, as well as extensions to the pattern language. Extending pattern matching to the Switch allows expressions to be tested, with specific operations for each pattern, so that complex data-oriented queries can be expressed succinctly and safely.

See JEP 406 for more details

JEP 409: Sealing Class (JDK-8260514)

specification

The Sealed Class has been added to the Java language. Sealed classes and interfaces restrict which other classes or interfaces can extend or implement them.

The sealed classes were delivered by JEP 360 as a preview feature in JDK 15. They were proposed again, and improved, by JEP 397 and provided as a preview feature in JDK 16. Now, in JDK 17, the sealed classes are being finalized, with no changes from JDK 16.

See JEP 409 for more details

JEP 382: New macOS Rendering pipeline (JDK-8238361)

client-libs/2d

The Swing API’s Java 2D API for rendering can now use the new Apple Metal Accelerated rendering API for macOS.

This is currently disabled by default, so rendering still uses the OpenGL APIS deprecated by Apple but still available and supported.

To enable metal, the application should specify its use by setting system properties:

-Dsun.java2d.metal=true
Copy the code

The use of Metal or OpenGL is transparent to the application because it is an internal implementation difference and has no impact on the Java API. Metal pipes require macOS 10.14.x or higher. Attempts to set it up on earlier versions will be ignored.

For more details, see [JEP 382 (openjdk.java.net/jeps/382)

Big ICONS access new API(JDK-8182043)

client-libs/javax.swing

Provides a new method in the JDK 17 javax.mail.. Swing filechooser. FileSystemView. GetSystemIcon (File, int, int), this approach allows the possible access to higher quality icon. It has been fully implemented for the Windows platform; However, the results on other platforms may be different and will be enhanced later. For example, by using this code:

FileSystemView fsv = FileSystemView.getFileSystemView();

Icon icon = fsv.getSystemIcon(new File("application.exe"), 64, 64);

JLabel label = new JLabel(icon);
Copy the code

Users can obtain higher quality ICONS for the application.exe file. This icon is useful for creating labels that can be extended better in the HighDPI environment.

DatagramSocket can be added directly to a multicast group (JDK-8237352)

core-libs/java.net

Java.net.DatagramSocket has been updated in this release to add support for joining multicast groups. It now defines join and leave multicast group methods. The java.net.DatagramSocket class-level API documentation has been updated to explain how to configure a normal DatagramSocket and use it to join and leave multicast groups.

This change means that the DatagramSocket API can be used for multicast applications without using the old java.net.MulticastSocket API. The MulticastSocket API works just as it did before, although most of its methods are deprecated.

For more information on the reason for this change, see CSRJDK-8260667

JEP 356: Enhanced pseudo-random number Generator (JDK-8193209)

core-libs/java.util

Provides new interface types and implementations for pseudo-random number generators (PRNG), including jump-able PRNG and an additional class of separable PRNG algorithms (LXM).

See JEP 356 for more details

Modernizing the Ideal Graph Visualizer (JDK-8254145)

hotspot/compiler

The Ideal Graph Visualizer (IGV) is a tool that has been modernized to visually and interactively explore the intermediate representations used in the HotSpot VM C2 just-in-time (JIT) compiler. Enhancements include:

  • Support for running IGV on up to JDK 15 (the latest version of IGV supported by the underlying NetBeans platform)
  • Faster, Maven-based IGV build system
  • Stabilization of block formation, group deletion, and node tracking
  • More intuitive shading and node sorting in the default filter
  • Rank fast node search with more natural default behavior

Modern IGVs are partially compatible with graphics generated from earlier JDK versions. It supports basic functions such as graphics loading and visualization, but ancillary functions such as node clustering and coloring may be affected.

For more information on building and running IGV, see github.com/openjdk/jdk…

New “New API” page and improved “Deprecated” page (JDK-8263468)

tools/javadoc(tool)

JavaDoc can now generate a page summarizing recent changes in the API. The list of the most recent versions to include is specified using the –since command line option. These values are used to find declarations that match @since because of the tag to be included on the new page. The — flame-label command line option provides the text to use in the title of the “New API” page.

On the Summary deprecated items page, you can view items grouped by version of deprecated items.

Source details in error messages (JDK-8267126)

tools/javadoc(tool)

When JavaDoc reports a problem in the input source file, it displays the source line of the problem in a manner similar to a compiler (JavAC) diagnostic message, along with the line containing the caret (^) that points to the location of the line.

In addition, log records and other “informational” messages are now written to the standard error stream, leaving the standard output stream for output specifically requested by command line options, such as command line help.

JEP 412: External Functions and Memory API (Incubation) (JDK-8265033)

core-libs

Introduce an API through which Java programs can interoperate with code and data outside of the Java runtime. By efficiently calling external functions (that is, code outside the JVM) and by securely accessing external memory (that is, memory not managed by the JVM), the API enables Java programs to call the local library and process native data without the vulnerabilities and dangers of JNI.

See JEP 412 for more details

Console Character Set API(JDK-8264208)

core-libs

Java.io.Console has been updated to define a new method that returns the Console’s Charset. The Charset returned may be different from the charset.defaultCharset () method. For example, it returns IBM437, while charset.defaultCharset () returns Windows-1252 on Windows (en-us). Please refer to the bugs.openjdk.java.net/browse/JDK-…

JDK Flight Recorder event for deserialization (JDK-8261160)

core-libs/java.io:serialization

You can now monitor deserialization of objects using the JDK Flight Recorder (JFR). When JFR is enabled and the JFR configuration includes deserialization events, JFR emits events every time a running program tries to deserialize an object. The deserialization event is called jFR. Derialization and is disabled by default. Deserialization events contain information used by the serialization filter mechanism; See the object input filter specification. In addition, if the filter is enabled, JFR events indicate whether the filter accepts or rejects deserialization of the object. For more information on how to use JFR deserialization events, see the article Monitoring deserialization to improve Application security. For reference information on using and configuring JFR, see the JFR runtime guide and the JFR Command Reference JDK task control file section.

JEP 415: Implementing context-specific deserialization filters (JDK-8264859)

core-libs/java.io:serialization

JEP 415: Context-specific deserialization Filters allow applications to configure context-specific and dynamically selected deserialization filters through a JVM-wide filter factory, which is called to select filters for each individual deserialization operation.

The Java Core Library Developer’s guide for serialization filtering introduces use cases and provides examples.

System properties of native character encoding names (JDK-8265989)

core-libs/java.lang

A new system property, native-.encode, was introduced. This system property provides the character encoding name of the underlying host environment. For example, it typically has UTF-8 on Linux and macOS platforms, and Cp1252 on Windows (EN-US). Please refer to the bugs.openjdk.java.net/browse/JDK-…

Add the Java. Time. InstantSource (JDK – 8266846)

core-libs/java.time

A new interface java.time.instantSource was introduced. This interface is an abstraction of java.time.clock, focusing only on the current moment and not referring to time zones.

Hex format and parsing utility (JDK-8251989)

core-libs/java.util

HexFormat provides hexadecimal to hexadecimal conversions for primitive types and byte arrays. Delimiters, prefixes, suffixes, and uppercase or lowercase options are provided by the factory method that returns the HexFormat instance.

Experimental Compiler Blackholes support (JDK-8259316)

hotspot/compiler

Added experimental support for Compiler Blackholes. These are useful for low-level benchmarks to avoid dead code elimination on the critical path without affecting benchmark performance. Current support is implemented as CompileCommand, accessible as -xx :CompileCommand=blackhole, with plans to eventually graduate this to the public API.

JMH has been able to automatically detect and use this facility when indicated/available. Consult the JMH documentation for next steps.

New Class hierarchy analysis implementation in HotSpot JVM (JDK-8266074)

hotspot/compiler

A new class hierarchy analysis implementation has been introduced in the HotSpot JVM. It features enhanced handling of abstractions and default methods, which improves inline decisions made by the JIT compiler. The new implementation replaces the original implementation and is turned on by default.

In order to help diagnosis possible problems related to new implementation, can by specifying – XX: + UnlockDiagnosticVMOptions – XX: – UseVtableBasedCHA command line marker to open the original implementation.

The original implementation may be removed in future releases.

JEP 391: macOS/AArch64 port (JDK-8251280)

hotspot/compiler

MacOS 11.0 now supports the AArch64 architecture. This JEP implements support for the MacOS-AARCH64 platform in the JDK. One of the added features is support for W^X (Write Xor Execute) memory. It is only enabled for MacOS-AARCH64 and can be extended to other platforms at some point. The JDK can be cross-compiled on Intel machines or compiled on Apple M1-based machines.

See JEP 391 for more details

Unified logging supports asynchronous log refresh (JDK-8229517)

hotspot/runtime

To avoid unwanted delays in threads using unified logging, users can now request that the unified logging system run in asynchronous mode. This can be done by passing the command line option -xlog :async. In asynchronous logging mode, the logging site queues all logging messages to a buffer. Individual threads are responsible for flushing them to the corresponding output. Intermediate buffers are bounded. When the buffer is exhausted, enqueued messages are discarded. The user can use the command-line option -xx :AsyncLogBufferSize=. To control the size of the intermediate buffer.

MacOS Early access available on ARM (JDK-8266858)

infrastructure/build

The new macOS is now available for ARM systems. An ARM port should behave like an Intel port. There are no known functional differences. When reporting problems on macOS, specify whether to use ARM or X64.

Support for specifying signers in Keytool -genkeypair (JDK-8260693)

security-libs/java.security

The -signer and -Signerkeypass options have been added to the -genkey pair command of the keytool utility. The -signer option specifies the keystore alias for the signer’s private key entry, and the -Signerkeypass option specifies the password used to protect the signer’s private key. These options allow keytool-genkey to sign the certificate using the signer’s private key. This is particularly useful for generating certificates with a key negotiation algorithm as a public key algorithm.

SunJCE provider supports KW and KWP modes through AES cryptography (JDK-8248268)

security-libs/javax.crypto

The SunJCE provider has been enhanced to support AES key wrap algorithm (RFC 3394) and AES key wrap algorithm with fill algorithm (RFC 5649). In earlier versions, the SunJCE provider supported RFC 3394 under the “AESWrap” cryptographic algorithm, which could only be used to wrap and unwrap keys. With this enhancement, two block cipher modes, KW and KWP, have been added to support data encryption/decryption and key packaging/unpacking using AES. For more details, see the “SunJCE providers” section of the “JDK provider documentation” guide.

New SunPKCS11 configuration properties (JDK-8240256)

security-libs/javax.crypto:pkcs11

The SunPKCS11 provider has added new provider configuration properties to better control the use of native resources. The SunPKCS11 provider uses native resources to work with the native PKCS11 library. To manage and better control native resources, additional configuration properties have been added to control how often native references are cleared and whether the underlying PKCS11 token is destroyed after logout.

The three new properties of the SunPKCS11 provider configuration file are:

  • DestroyTokenAfterLogout (Boolean value, the default value is false) if set to true, then the SunPKCS11 provider instance call Java security. AuthProvider. Logout (), the basic token object will be destroyed, Resources will be freed up. This essentially makes the SunPKCS11 provider instance unavailable after the logout() call. Note that PKCS11 providers with this property set to true should not be added to the list of system providers because the provider object is not available after the logout() method is called.
  • Cleaner. shortInterval (integer, default is 2000, in milliseconds) This defines how often native references are cleared during busy periods, that is, how often the Cleaner thread should process native references that are no longer needed in the queue to free up native memory. Note that the Cleaner thread will switch to the “longInterval” frequency after 200 failed attempts, when no reference is found in the queue.
  • Cleaner.longinterval (integer, default is 60000, in milliseconds) This defines how often native references should be checked during non-busy periods, that is, how often the Cleaner thread should check native references in the queue. Note that if a native PKCS11 reference for cleaning is detected, the Cleaner thread switches back to the “short interval” value.

Configurable extensions with system properties (JDK-8217633)

security-libs/javax.net.ssl

Two new system properties have been added. System property JDK. TLS. Client. DisableExts used to disable the use of TLS extension of the client. System property JDK. TLS. Server disableExts used to disable the server using the TLS expand. If extensions are disabled, they are neither generated nor processed in the handshake message.

Attribute strings are comma-separated lists of standard TLS extension names registered in IANA documents (for example, server_name, status_REQUEST, and signature _ALGORITHms_cert). Note that the extension is case sensitive. Unknown, unsupported, misspelled, and duplicate TLS extension name tokens will be ignored.

Note that the implications of blocking TLS extensions are complex. For example, if forced extension is disabled, you may not be able to establish a TLS connection. Do not disable forced extensions, and do not use this feature unless you clearly understand its impact.

“Related Packages” on the Package Summary page (JDK-8260388)

tools/javadoc(tool)

The Summary page for Packages now includes a section that lists any “Related Packages.” Related Packages are determined according to common naming convention heuristics and may include the following:

  • “Parent” package (that is, a package is a package of child packages)
  • Sibling packages (that is, other packages with the same parent package)
  • Any child package

Related packages are not necessarily in the same module.

The original link

This article is the original content of Aliyun and shall not be reproduced without permission.