Java Versions and Features

Muhammed Öner
7 min readJun 25, 2021

Java Version History

What is the latest Java version?

As of March 2021, Java 16 is the latest released Java version.

Java Versions History

Java Features 9–16

Java 9

Java 9 was a fairly big release, with a couple of additions:

Collections

Collections got a couple of new helper methods, to easily construct Lists, Sets and Maps.

List<String> list = List.of("one", "two", "three");Set<String> set = Set.of("one", "two", "three");Map<String, String> map = Map.of("foo", "one", "bar", "two");

Streams

Streams got a couple of additions, in the form of takeWhile, dropWhile, iterate methods.

Stream<String> stream = Stream.iterate("", s -> s + "s").takeWhile(s -> s.length() < 10);

Optionals

Optionals got the sorely missed ifPresentOrElse method.

user.ifPresentOrElse(this::displayAccount, this::displayLogin);

Interfaces

Interfaces got private methods:

public interface MyInterface {
private
static void myPrivateMethod(){
System.out.println("I am private!");}
}

Java 10

There have been a few changes to Java 10, like Garbage Collection etc. But the only real change you as a developer will likely see is the introduction of the “var”-keyword, also called local-variable type inference.

Local-Variable Type Inference: var-keyword

// Pre-Java 10String myName = "Muhammed";// With Java 10var myName = "Muhammed"

Java 11 (LTS)

Java 11 was also a somewhat smaller release, from a developer perspective.

Strings & Files

Strings and Files got a couple new methods (not all listed here):

"Muhammed".isBlank();"Muham\nmed".lines();"Muhammed  ".strip();Path path = Files.writeString(Files.createTempFile("helloworld", ".txt"), "Hi, my name is!");String s = Files.readString(path);

Run Source Files

Starting with Java 10, you can run Java source files without having to compile them first. A step towards scripting.

ubuntu@DESKTOP-168M0IF:~$ java MyScript.java

Local-Variable Type Inference (var) for lambda parameters

The header says it all:

(var firstName, var lastName) -> firstName + lastName

HttpClient

The HttpClient from Java 9 in its final, non-preview version.

Other stuff

Flight Recorder, No-Op Garbage Collector, Nashorn-Javascript-Engine deprecated etc.

Java 12

Java 12 got a couple new features and clean-ups, but the only ones worth mentioning here are Unicode 11 support and a preview of the new switch expression, which you will see covered in the next section.

Java 13

Essentially you are getting Unicode 12.1 support, as well as two new or improved preview features (subject to change in the future):

Switch Expression (Preview)

Switch expressions can now return a value. And you can use a lambda-style syntax for your expressions, without the fall-through/break issues:

Old switch statements looked like this:

switch(status) {case SUBSCRIBER:// code blockbreak;case FREE_TRIAL:// code blockbreak;default:// code block}

Whereas with Java 13, switch statements can look like this:

boolean result = switch (status) {case SUBSCRIBER -> true;case FREE_TRIAL -> false;default -> throw new IllegalArgumentException("something is murky!");};

Multiline Strings (Preview)

You can finally do this in Java:

String htmlBeforeJava13 = "<html>\n" +"    <body>\n" +"        <p>Hello, world</p>\n" +"    </body>\n" +"</html>\n";String htmlWithJava13 = """<html><body><p>Hello, world</p></body></html>""";

Java 14

Switch Expression (Standard)

The switch expressions that were preview in versions 12 and 13, are now standardized.

int numLetters = switch (day) {case MONDAY, FRIDAY, SUNDAY -> 6;case TUESDAY                -> 7;default      -> {String s = day.toString();int result = s.length();yield result;}};

Records (Preview)

There are now record classes, which help alleviate the pain of writing a lot of boilerplate with Java.

Have a look at this pre Java 14 class, which only contains data, (potentially) getters/setters, equals/hashcode, toString.

final class Point {public final int x;public final int y;public Point(int x, int y) {this.x = x;this.y = y;}}

With records, it can now be written like this:

record Point(int x, int y) { }

Again, this is a preview feature and subject to change in future releases.

Helpful NullPointerExceptions

Finally NullPointerExceptions describe exactly which variable was null.

author.age = 28;---Exception in thread "main" java.lang.NullPointerException:Cannot assign field "age" because "author" is null

Pattern Matching For InstanceOf (Preview)

Whereas previously you had to (cast) your objects inside an instanceof like this:

if (obj instanceof String) {String s = (String) obj;}

You can now do this, effectively dropping the cast.

if (obj instanceof String s) {System.out.println(s.contains("hello"));}

Packaging Tool (Incubator)

There’s an incubating jpackage tool, which allows to package your Java application into platform-specific packages, including all necessary dependencies.

· Linux: deb and rpm

· macOS: pkg and dmg

· Windows: msi and exe

Garbage Collectors

The Concurrent Mark Sweep (CMS) Garbage Collector has been removed, and the experimental Z Garbage Collector has been added.

Java 15

Text-Blocks / Multiline Strings

Introduced as an experimental feature in Java 13 (see above), multiline strings are now production-ready.

String text = """Lorem ipsum dolor sit amet, consectetur adipiscing \elit, sed do eiusmod tempor incididunt ut labore \et dolore magna aliqua.\""";

Sealed Classes — Preview

If you ever wanted to have an even closer grip on who is allowed to subclass your classes, there’s now the sealed feature.

public abstract sealed class Shapepermits Circle, Rectangle, Square {...}

This means that while the class is public, the only classes allowed to subclass Shape are Circle, Rectangle and Square.

Records & Pattern Matching

The Records and Pattern Matching features from Java 14 (see above), are still in preview and not yet finalized.

Nashorn JavaScript Engine

After having been deprecated in Java 11, the Nashorn Javascript Engine was now finally removed in JDK 15.

ZGC: Production Ready

The Z Garbage Collector is not marked experimental anymore. It’s now production-ready.

Java 16

Unix-Domain Socket Channels

You can now connect to Unix domain sockets (also supported by macOS and Windows (10+).

socket.connect(UnixDomainSocketAddress.of("/var/run/postgresql/.s.PGSQL.5432"));

Foreign Linker API — Preview

A planned replacement for JNI (Java Native Interface), allowing you to bind to native libraries (think C).

Records & Pattern Matching

Both features are now production-ready, and not marked in preview anymore.

Sealed Classes

Sealed Classes (from Java 15, see above) are still in preview.

Java 8 (LTS) vs Java 11 (LTS)

Average Difference : 16.1%

Average Difference : 4.5%

Java 11 (LTS) vs Java 15

Average Difference : 11.24%

Average Difference : 13.85%

Average Difference : 11.03%

Java 8 (LTS) Most Important Features

1. forEach() method in Iterable interface

2. default and static methods in Interfaces

3. Functional Interfaces and Lambda Expressions

4. Java Stream API for Bulk Data Operations on Collections

5. Java Time API

6. Collection API improvements

7. Concurrency API improvements

8. Java IO improvements

Java 11 (LTS) Most Important Features

1. Running Java File with single command

2. New utility methods in String class

3. Local-Variable Syntax for Lambda Parameters

4. Nested Based Access Control

5. JEP 321: HTTP Client

6. Reading/Writing Strings to and from the Files

7. JEP 328: Flight Recorder

Java 15 Most Important Features

1. JEP 339: Edwards-Curve Digital Signature Algorithm (EdDSA)

2. JEP 360: Sealed Classes (Preview)

3. JEP 371: Hidden Classes

4. JEP 372: Remove the Nashorn JavaScript Engine

5. JEP 374: Disable and Deprecate Biased Locking

6. JEP 375: Pattern Matching for instanceof (Second Preview)

7. JEP 377: ZGC: A Scalable Low-Latency Garbage Collector

8. JEP 378: Text Blocks

9. JEP 379: Shenandoah: A Low-Pause-Time Garbage Collector

10. JEP 381: Remove the Solaris and SPARC Ports

11. JEP 383: Foreign-Memory Access API (Second Incubator)

12. JEP 384: Records (Second Preview)

13. JEP 385: Deprecate RMI Activation for Removal

Conclusion

Pros and Cons To Upgrade Java Version

Pros

+Huge performance Upgrade

+Amazing new Features

+Better compatible with higher Spring versions

Cons

-Licensing

Back in 2018 Oracle announced fundamental changes to the way in which Java is licensed. From 2019, if an organization makes commercial use of Java 11+ then they must pay for it. This means that moving from Java 8, to the next LTS version Java 11, could have significant financial or legal implications. In some cases, this has certainly been a limiting factor in the adoption of Java 11.

-Long Term Support (LTS) Version

One of the key reasons why Java 8 is still so popular is that it is an LTS (or Long-Term Support) version. Unfortunately, not all versions of Java are LTS versions! Since this policy was introduced only Java 8 (2014) and Java 11 (2018) have been designated as having LTS. This means that all intervening releases, including Java 14 and the planned Java 15 (September 2020) do not have LTS.

From a commercial point of view no organization should be considering putting a system into production that relies on a version of Java that does not have LTS. It is also worth noting that, although Oracle ended free support for Java 8 in January 2019 for commercial use (and will end it for personal use in December 2020), it is possible to pay for commercial support for Java 8 until December 2030.

-Unsupported Libraries

-Migration will take a lot time by big projects

Sources

https://www.marcobehler.com/guides/a-guide-to-java-versions-and-features

https://www.optaplanner.org/blog/2019/01/17/HowMuchFasterIsJava11.html

https://www.frameworktraining.co.uk/blog/why-is-java-8-more-popular-than-java-14/

https://www.azul.com/blog/jdk-15-release-64-new-features-and-apis/

https://www.baeldung.com/java-15-new

https://www.techgeeknext.com/java/java15-features

--

--