Which Java version should be installed

Which Java version should be installed

What is the latest Java version?

As of March 2023, Java 20 is the latest released Java version. In September 2023, Java 21 will follow. The current long-term support version (LTS) of Java is Java 17, released in September 2021.

What Java version should I use?

Newer Java versions now follow every 6 months. Hence, Java 21 is scheduled for September 2023, Java 22 for March 2024 and so on. In the past, Java release cycles were much longer, up to 3-5 years. This graphic demonstrates that:

With that many new versions coming out, there’s basically these real-world(™) usage scenarios:

  • Legacy projects in companies are often stuck with using Java 8 (see Why are companies still stuck with Java 8?) . Hence you will be forced to use Java 8 as well.
  • Some legacy projects are even stuck on Java 1.5 (released 2004) or 1.6 (released 2006) - sorry, folks, I feel for you!
  • If you are making sure to use the very latest IDEs, frameworks and build tools and starting a greenfield project, you can, without hesitation, use Java 17 (LTS) or even the very latest Java 19.
  • There’s the special field of Android development, where the Java version is basically stuck at Java 7, with a specific set of Java 8 features available. Or you switch to using the Kotlin programming language.

Why are companies still stuck with Java 8?

There’s a mix of different reasons some companies are still stuck with Java 8. To name a few:

  • Build tools (Maven, Gradle etc.) and some libraries initially had bugs with versions Java versions > 8 and needed updates. For example, certain build tools like Maven would print out "reflective access"-warnings when building Java projects, which simply "felt not ready", even though the builds were fine.
  • Up until Java 8 you were pretty much using Oracle’s JDK builds and you did not have to care about licensing. Oracle changed the licensing scheme In 2019, though, which led the internet go crazy with a ton of articles saying "Java is not free anymore" - and a fair amount of confusion followed. This is however not really an issue, which you’ll learn about in the Java Distributions section of this guide.
  • Some companies have policies to only use LTS versions and rely on their OS vendors to provide them these builds, which takes time.

To sum up: you have a mix of practical issues (upgrading your tools, libraries, frameworks) and political issues.

Why are some Java versions, like 8 also called 1.8?

Java versions before 9 simply had a different naming scheme. So, Java 8 can also be called 1.8, Java 5 can be called 1.5 etc. When you issued the 'java -version' command.

Java 17 is the latest LTS(Long Term Support) version of the Java programming language, released on September 14, 2021. If you’re currently using Java 11, it may be time to consider migrating to Java 17 to take advantage of its new features and improvements. In this article, we’ll discuss what’s new in Java 17, although some of the features discussed here have been introduced in version following up to Java 17 from Java 11.

Why should we move from Java 11?

Article content

Although Java 11 is also an LTS version and is used by many application, there are some major reasons why we might want to shift to Java 17.

  1. Ending Support for Java 11: Java 11 will be supported till September 2023 and extended support will be provided till September 2026. This means that after the support ends, we would have no patches(not even the security ones).
  2. Spring 6: The latest version of Spring, Spring 6 will require Java 17 to work, and as there are many libraries which work along with them, they would also be moving to Java 17. If your applications rely on the Spring Framework, you should definitely consider moving to Java 17.
  3. Free Oracle JDK present for Java 17: Java 17 is issued under the new NFTC (Oracle No-Fee Terms and Conditions) license. It is therefore again allowed to use the Oracle JDK version for free for production and commercial use.(was not allowed for Java 11.

What's new in Java 17?

With Java 17 , there have been several improvements and new features introduced which will have long term support.

Text Blocks

Java has introduced text blocks to make the code more readable and to avoid unnecessary string formatting. Now, we can place our text in between the triple quotes and have multiple double quoted strings inside it without having to use escape characters.

Improved Switch Statements

Switch Expressions will allow you to return values from the switch case and use these return values in assignments, etc. Java allows use of operator ->(arrow) instead of : (colon) to denote the return expression. break keyword will not be needed when returning using switch in this expression, but default case is required.

Null Pointer Exception

In Java 11 , when we get a Null Pointer Exception, we only get the line number on which the exception occurred but we don’t get the method or variable which resolved to null. With Java 17, the messaging has been improved as the NullPointerException message also tells us the exact method invocation which caused the NullPointerException.witch Statements

Switch Expressions will allow you to return values from the switch case and use these return values in assignments, etc. Java allows use of operator ->(arrow) instead of : (colon) to denote the return expression. break keyword will not be needed when returning using switch in this expression, but default case is required.

Null Pointer Exception

In Java 11 , when we get a Null Pointer Exception, we only get the line number on which the exception occurred but we don’t get the method or variable which resolved to null. With Java 17, the messaging has been improved as the NullPointerException message also tells us the exact method invocation which caused the NullPointerException.

Compact Number Formatting Support

A factory method is added to NumberFormat class in order to format numbers in compact, human-readable form according to the Unicode standard. There is a SHORT and LONG format available.

Article content


Performance Benchmarks

Java 17 has also shown improvement over Java 11 in terms of its memory usage and time complexity. One such benchmark has been done where they tally code written in both version on their performance by making them do a series of tasks. The complete results and task descriptions can be found here.

Some of the general results which have been noted are:

  1. Java 17 is 8.66% faster than Java 11 and 2.41% faster than Java 16 for G1GC (default garbage collector).

2. Java 17 is 6.54% faster than Java 11 and 0.37% faster than Java 16 for ParallelGC(Parallel Garbage Collector).

3. The Parallel Garbage Collector(Available in Java 17) is 16.39% faster than the G1 Garbage Collector(Used in Java 11).

Migrating from Java 11 to Java 17 can provide many benefits, including new features and improved performance. However, it’s essential to be aware of potential bottlenecks that may arise during the migration process. Many libraries would also be upgrading to newer versions to support Java 17. Hence we should be extremely careful if we are using external libraries in our projects. By understanding these potential issues and taking the necessary steps to address them, you can ensure a smooth and successful migration to Java 17.

> Build tools (Maven, Gradle etc.) and some libraries initially had bugs with versions Java versions > 8 and needed updates. For example, certain build tools like Maven would print out "reflective access"-warnings when building Java projects, which simply "felt not ready", even though the builds were fine. First Maven worked with JDK9.. yes there had some small issues in the beginning (about the versions in some components did something wrong)... but they have fixed fast... The referenced WARNING is related to Groovy which has an issue not Maven ...Apart from that those warnings would not have prevented anyone of using JDK9+ for building...

To view or add a comment, sign in

More articles by Bhavishya Ambati

Others also viewed

Explore content categories