» Home » Java 17: These 5 New Features Makes Java 17 Special

Java 17: These 5 New Features Makes Java 17 Special

by Imran Shaikh
5123 views
Java 17: These 5 New Features Makes Java 17 Special

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 personally think will affect me on my project if I use Java 17. There are other features as well which are great and required for 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?


You can follow me on social media via @coderstea on TwitterLinkedinFacebook, or Instagram. We also share high-quality videos about programming on our Youtube channel. You can also publish your own post on CodersTea.com, just share your thought on Contact Us or let us know in the comments.


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. Meaning, 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 which the 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 really 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 or interface can extend or implement this class or interface. In short, 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 an error if they try to extend it.

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

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 extends RandomGenerator 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 existing behavior of class java.util.Random

Java’s Focus on Enhanced Security

With JEP 403, Java is strongly encapsulating JDK internals. Meaning, it will restrict users to directly use 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 rather a step towards 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 switch 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();
};

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

Conlusion and Other Features and Updates in Java 17

As I said earlier, these were the features that I personally 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 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!!!

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

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

Privacy & Cookies Policy
1
0
Would love your thoughts, please comment.x
()
x