Home Java Java 17: These 5 New Features Make Java 17 Special

Java 17: These 5 New Features Make Java 17 Special

Published: Last Updated on 1 comment

Hey, Tea Lovers! Java 17 is about to release in September 2021, so I thought now would be a great time to give you some updates on what is there in Java 17. I list down some key points about Java 17, that makes it special.

This list is generated based on what I think will affect me on my project if I use Java 17. There are other features as well which are great and required for the enhancement of Java. I list them down at the end of the post to read them in more detail. Now let’s look at the features, shall we?


I would be happy to connect with you guys on social media. It’s @coderstea on TwitterLinkedinFacebook, Instagram, and YouTube.

Please Subscribe to the newsletter to know about the latest posts from CodersTea.


Java 17 is An LTS Release

Java 17 will be a Long Term Support aka an LTS release.

As you must have known that Java has adopted a 6-month release cycle. This means it will release a new version of Java every 6 months. And after every 3 years, an LTS version will be released. Currently, Java 11 is the LTS version, released in September 2018. But After Java 17 releases, it will be the latest LTS support.

Many organizations rely on LTS versions, so they are using Java 11. But After Java 17 releases they will use Java 17 (probably).

Since releasing Java 9 to Java 16, Java has added a lot of features and improvements for that Java developers were longing for. And looking at it, we can say that Java is slowly and steadily catching up to the other programming languages. It makes a Java Developer feel happy, as we were tired of hearing “Java is Dead“.

If your organization is using Java 11 then read my post about Java 11: The Things I Love and Use from Java 11.

Sealed Classes in Java 17

As mentioned in my previous post about new features in Java 16, I talked about the preview feature “Sealed Classes”. It is now out of the incubator and available in the actual or core library of Java 17.

The sealed class allows one to describe which class/interface can extend/implement the current class/interface. Meaning we can put restrictions on who can use this class or interface. Suppose we have  Student  abstract class and if we make it a sealed class and permit only  ScienceStudent  and  CommerceStudent to extend the class, then only those classes will be able to extend the Student and other classes will get a compilation error if they try to extend it.

Please read the detailed post on Java Sealed Classes: The Ultimate Guide to Secure Code

public abstract sealed class Student permits ScienceStudent , CommerceStudent { ... }

public final class ScienceStudent extends Student {...}
public non-sealed class CommerceStudent extends Student {...}

// Compilation error :  class is not allowed to extend sealed class
public final class RandomStudent extends Student {...}Code language: PHP (php)

This provides a more declarative approach than the access modifier to restrict the use of superclasses.

Java 17 Provides A Better Random Generator

Java 17 provides new interface types and implementations for pseudorandom number generators (PRNGs). It has introduced a new interface named RandomGenerator. The goal of this interface is to supply a uniform API for all existing and new PRNGs.

RandomGenerators provide methods named  intslongs,  doublesnextBooleannextIntnextLongnextDouble, and  nextFloat, with all their current parameter variations. Following are the provided four new specialized RandomGenerator interfaces:

  • SplittableRandomGenerator 
  • JumpableRandomGenerator 
  • LeapableRandomGenerator 
  • ArbitrarilyJumpableRandomGenerator 

All these interfaces extend RandomGenerator the interface.

The goal of this feature is to

  • Make it easier to use various PRNG algorithms interchangeably in applications.
  • Better support stream-based programming by providing streams of PRNG objects.
  • Eliminate code duplication in existing PRNG classes.
  • Carefully preserve the existing behavior of the class java.util.Random

Java’s Focus on Enhanced Security

With JEP 403, Java is strongly encapsulating JDK internals. This means it will restrict users from directly using the internal contents of Java and encourage users to use standard APIs. The reason being using internals may cause issues, especially in security. The goal of this feature is to:

  • Continue to improve the security and maintainability of the JDK, which is one of the primary goals of Project Jigsaw.
  • Encourage developers to migrate from using internal elements to using standard APIs, so that both they and their users can upgrade without fuss to future Java releases

Another security update is JEP 411: Deprecate the Security Manager for Removal. Well, not exactly an update but rather a step toward the removal of a feature. The Security Manager dates from Java 1.0. It has not been the primary means of securing client-side Java code for many years, and it has rarely been used to secure server-side code. So in the upcoming Java release, it will be completely removed from Java.

Preview for Pattern Matching for Switch

This feature introduces an advanced version of the switch case. It’s a preview feature and won’t be available in the standard package.

In Java 16 we got the feature “Pattern Matching of instanceOf”. Similarly, this switching pattern matching feature will improve the switch expression from plain old single equals type. Here is a glimpse of a code for switch expression.

Object o = 123L;
String formatted = switch (o) {
    case Integer i -> String.format("int %d", i);
    case Long l    -> String.format("long %d", l);
    case Double d  -> String.format("double %f", d);
    case String s  -> String.format("String %s", s);
    default        -> o.toString();
};Code language: JavaScript (javascript)

You can see more examples and detailed explanations about this feature on JEP 406.

Conclusion and Other Features and Updates in Java 17

As I said earlier, these were the features that I think will affect our choice to use Java 17. But there is a total of 14 new features in Java 17. Here is the list of features:

JEP 306Restore Always-Strict Floating-Point Semantics
JEP 356Enhanced Pseudo-Random Number Generators
JEP 382New macOS Rendering Pipeline
JEP 391macOS/AArch64 Port
JEP 398Deprecate the Applet API for Removal
JEP 403Strongly Encapsulate JDK Internals
JEP 406Pattern Matching for a switch (Preview)
JEP 407Remove RMI Activation
JEP 409Sealed Classes
JEP 410Remove the Experimental AOT and JIT Compiler
JEP 411Deprecate the Security Manager for Removal
JEP 412Foreign Function & Memory API (Incubator)
JEP 414Vector API (Second Incubator)
JEP 415Context-Specific Deserialization Filters
Java 17 Feature List (credit: OpenJDK)

See you in the next Post. HAKUNA MATATA!!!


I would be happy to connect with you guys on social media. It’s @coderstea on TwitterLinkedinFacebook, Instagram, and YouTube.

Please Subscribe to the newsletter to know about the latest posts from CodersTea.


Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Ads
Ads
Ads

@2023 All Right Reserved. Designed and Developed by CodersTea

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More