Java 17 Features

Oracle released its new Long Term Support (LTS) release of java : Release 17 on September 13th 2021. With this new release, Oracle introduced a new licensing terms and conditions as well under the so called “Oracle — No Fee Terms and Conditions (NFTC)”.

Java 17 is an LTS version. Other LTS JDKs are Java 8 and Java 11. LTS JDKs are released every three years where as non-LTS are released every six months. In comparison, LTS versions’ support lasts for several years, whereas the non-LTS JDKs’ support lasts only six months, ending when the next non-LTS is released.

Although Java 17 is a LTS version, there are no major updates. JEP 406 and JEP 409 are very useful and important for any java developer.

JEP 406 : Pattern Matching for Switch (Preview)

  • Expand the expressiveness and applicability of switch expressions by allowing patterns to appear in case labels.
  • Allow the historical null-hostility of switch to be relaxed when desired.
  • Introduced two new patterns : guarded and parenthesized patterns.

Before Java 17 :

1*dyVG-o8iuZdDR0S4ssQGxQ

Now after Java 17 enhancements, we can refactor the above code like this :

1*boW-ZUsMt-7FjpMuoIf2pA

Guarded Pattern : Uses pattern && boolean expression for further refinement of the pattern.

1*tPZzcDxOk_JdZupOyAZ-JA

JEP 409 : Sealed Classes

Enhance the java programming with sealed classes and interfaces. Sealed classes and interfaces restrict which other classes or interfaces may extend or implement them.

  • Uses sealed modifier in declaration and the permits clause to specify classes that are allowed to extend sealed class.
1*F2eW_-hnd0IHPuylxt5PwQ
  • The sub-class must be final, seal or non-sealed.

Post a Comment

Previous Post Next Post