What has changed in Java 17?

On September 14, 2021, the Java language and runtime platform Java 17 under Long-Term Support (LTS) was released. What’s new in Java 17 and should you upgrade? Let’s find out.

Older Java versions, such as Java 11 and Java 8, which were released with longer support, are still widely used in many applications.

Why is it important for organizations to update to the most recent Java version? It takes work to update to Java 17, mostly to utilize the new JVM capabilities and functionalities to their fullest.

To easily upgrade to Java 17 with the least amount of time and effort, many firms use Docker and Docker images. When using Docker images, developers may create their own continuous integration/deployment (CI/CD) pipelines. Other teams using earlier Java versions won’t be impacted because they may still use previous Docker images.

Features of Java 17

macOS and AArch64 support

Enhancing support for macOS on the AArch64 architecture with JEP 391 is one of the crucial JVM changes included in this release. The most recent series of CPUs (M1) that Apple delivered with their laptops in the previous year will be supported by it.

Since some manufacturers have released JDK versions that support this architecture and even return support up from Java 8, it may not be a huge concern for consumers on such platforms. To guarantee that the platform will be maintained and supported in the future, the official stamp of approval is necessary. Java 9 now supports the Linux/AArch64 platform, while Java 16 now supports the Windows/AArch64 platform.

Sealed Classes

In Java 17, a new feature known as sealed classes was included. Following a successful testing period, Java 17 now officially recognizes sealed Classes as a platform and language. A developer can use it to limit the subtypes that a type may have and stop others from extending or using it in an unintended way.

When you attempt to transform an unsealed type into a non-permitted subtype using sealed classes, the compiler is also able to produce problems at build time. For AWT/Swing programs that use the Apple Metal API rather than OpenGL to operate on macOS, Java 17 also introduces a new rendering process. It now offers a better API and more advanced random number generation features.

Java 17: Additions, Subtractions, and Limitations

A number of additions, removals, and new restrictions are also included in Java 17.

JDK Internals Encapsulation

The JDK Internals encapsulation process’ conclusion is one modification. This was initially made available in Java 9, and it would issue runtime warnings if a user tried to utilize reflection or a similar feature to get around the typical limitations on utilizing internal APIs. To control this behavior, command-line parameters were also included.

Since Java 9, several APIs have been developed to provide a consistent approach to do the most frequent operations; users would internally use these APIs. The default behavior was altered with Java 16 from issuing a warning to blocking access to raising an exception. To change the behavior, it makes use of a command-line option.

It is possible to turn off this limitation using Java 17, which does away with the command-line option. All unauthorized access to those internal APIs is thus now prohibited.

Always-Strict Floating Point semantics

Reintroducing Always-Strict Floating Point semantics might be referred to as a further « removal ». In order to increase efficiency, the JVM can trade up a minor bit of precision in floating-point computations thanks to changes made to the floating-point semantics default in Java in Java 1.2. There is now a strictfp keyword for classes and methods that require strict semantics. Since then, different instruction set types have been added to CPUs, enabling strict floating-point semantics to be employed without incurring extra costs. There is no longer a requirement to provide strict or default semantics.

The prior default semantics are gone in Java 17, and all floating-point operations are carried out rigorously. The phrase « strictfp » is still in use. It generates a warning at compile time but has no effect.

Ahead-of-Time (AOT) Compilation

A JIT code was created utilizing Java 9’s experimental ahead-of-time (AOT) compilation technology, which makes use of the Graal compiler. By integrating the JVMCI interface, Java 10 enabled the Graal compiler to be used in OpenJDK as a JIT compiler. It has greatly improved since it was published. Significant improvements have been made to the Graal compiler, which now has a JVM known as the GraalVM.

RMI activation

After being removed from Java 8 in JEP 407, RMI activation was eventually abandoned and designated as a prerequisite for removal in Java 15 after being deprecated since that version of Java. A way to make dispersed objects and on-demand resources available through RMI is given by RMI Activation. It was seldom ever used, though, and a superior replacement is now readily accessible. The removal of the Activation section has no impact on the remaining parts of RMI.

Applet API Removal

After initially being eliminated in Java 9, the Applet API has now been marked for removal by JEP 398. Java AWT/Swing controls might be integrated into a web page within a browser using the Applet API. However, no current browser can handle this, hence over the past ten or so years, Applets have virtually been unreachable.

Security Manager

The security manager (JEP 411) is the deprecation that is most important. Since the release of Java 1.0, Security Manager has been in use. Its purpose was to limit what Java could do locally on the computer, such as preventing access to networks, files, and other network resources. Additionally, by restricting reflection and certain APIs, it tries to sandbox unreliable code.

Java 12 marked the beginning of Security Manager’s demise. To prohibit the usage of the security manager during runtime, a command-line parameter was introduced. As a result of the change implemented in Java 17, a runtime warning will be produced in the JVM whenever a Security Manager is attempted to be configured, either dynamically at runtime or via the command line.

Preview and Incubator Features

Given that Java 17 was touted as being a long-term supported version, many people questioned if it would have any preview and incubator capabilities. Java 17 contains a preview function and two incubator modules!

Vector API

The second stage of the incubation for Vector API (JEP 414) is now underway. Developers may describe vector computation using the API, and the JIT compiler will translate those definitions into the proper vector instructions allowed by the CPU architecture of the JVM (for example, using the SSE or AVX instructions sets).

In the past, programmers were forced to create native libraries tailored to each platform or utilize scalar functions. A smooth fallback method, which was difficult in prior versions, is also provided by the Vector API implementation in Java.

The classes in the JDK are able to use the Vector API because of its standardization. Instead of needing to build and maintain numerous platform-specific implementations inside the JVM, Java Arrays mismatch () methods may be altered to execute on Java, which would free up resources.

Foreign Function & Memory API

The Foreign Function & Memory API (JEP 412) is a further incubator function. The Foreign Linker API (JEP 389) and the Foreign-Memory API (JEP 393) are two additional Java 16 incubator modules that have evolved and merged into this one. By utilizing Java-based statically-typed programming, they both offer access to native memory and code.

Pattern Matching for Switch

Pattern Matching for Switch (JEP 406) is the last component of the language preview added to Java 17. Similar to the syntax employed by Pattern Matching (JEP 394), which became the de facto norm with Java 16, this language feature extends the switch expressions and statements in accordance with the type.

In the past, you had to create an if-else chain using an instance of checks like these if you wanted to do various actions based on the dynamic nature of an object:

Combining the switch expression with the new switch pattern matching functionality, the procedure may be simplified to something like:

As you may have noted, a variable declaration is taking place as the check is being performed. The matching of instance shows, like the other variables in the Pattern, that this object was type-checked, cast, and is accessible from the variable inside its current region.

Another step in the direction of pattern matching is the preview feature. The ability to deconstruct arrays and records is the following stage.

Upgrade to Java 17: Should You?

Yes, you should always update to the most recent version, but not right away. You might need to wait a while before it’s finished since the programs and libraries you use might not have been updated to support Java 17.

There are several choices inside the language and within the JVM itself that need an update to Java 17 if you’re stuck with an LTS version of Java like Java 8 or Java 11. Given that it is a long-term maintenance release, there is a good probability that Java 17 will ultimately be upgraded in your production environment as well.

The most cost-effective course of action is definitely to transition to Java 17 as soon as possible since it lowers the expenses of switching, especially if you’re starting a brand-new project or are in the midst of getting your existing project ready for Java 17. This also makes it possible for the project’s developers to make use of all the newest features and operational aspects.

Take advantage of all the advancements that have been made in the last several years, such as new low-latency garbage collector implementations and increased support for Java-based container systems.

Recommended For You

About the Author: Ismaïl

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *