I’m going to ask Hossein Koraee in this article what is the difference between different versions of Java? I’ll answer with the example. From the release of Java 8, to version 17, Java was formed with 194 JDK Enhancement Proposals (JEPs), each bringing improvements to its version. This article has prepared a summary of categorized and regulated lists of the most important developments.

You can see the list of JEPs for each version at the link.

All features are generally available and enabled by default, unless labeled with one of the following:

Preview :

The features are quite clear and executed, but have yet to be finalized. They are deemed almost perfect, but they need real-world feedback for final activation.

Experimental :

These characteristics are not stable and are likely to change.

Incubator :

There are tools and APIs that have not been finalized and distributed in separate modules.

New Language Features:

Since Java 8 has made a lot of improvements in language. This section summarizes what has happened in previous years.

  • Sealed classes can restrict classes that may extend them:
    JDK 17 (Preview In JDK 16 and JDK 15)
    public abstract sealed class Shape
        permits Circle, Rectangle {...}
    
    public class Circle extends Shape {...} // OK
    public class Rectangle extends Shape {...} // OK
    public class Triangle extends Shape {...} // Compile error
    
    No need for default case if all permitted types are covered
    double area = switch (shape) {
        case Circle c -> Math.pow(c.radius(), 2) * Math.PI
        case Rectangle r -> r.a() * r.b()
    };
  • Switch support for pattern matching:
    JDK 17
    String formatted = switch (o) {
        case Integer i && i > 10 -> String.format("a large Integer %d", i);
        case Integer i -> String.format("a small Integer %d", i);
        case Long l -> String.format("a Long %d", l);
        default -> o.toString();
    };
  • Simplification for defining record classes:
    JDK 16 (Preview In JDK 15 and JDK 14)
    record Point(int x, int y) { }
      
    var point = new Point(1, 2);
    point.x(); returns 1
    point.y(); returns 2
  • Pattern Matchings need cast-off to instanceof:
    JDK 16 (Preview In JDK 15 JDK 14) 
    if (obj instanceof String s && s.length() > 5) {
              System.out.println("obj is a String with more than 5 characters: " + s.toUpperCase()); 
    }
  • Text Block:
    JDK 15 (Preview In JDK 14 JDK 13)
    String html = """            <html>
                    <body>
                        <p>Hello, world</p>
                    </body>
                </html>""";
  • Generalization of handeling of Null errors:
    JDK 15
    a.b.c.i = 99;
    ---
    Exception in thread "main" java.lang.NullPointerException:
          Cannot read field "c" because "a.b" is null
  • Switch phrase:
    JDK 14 (Preview In JDK 12 JDK 13)
    int numLetters = switch (day) {
        case MONDAY, FRIDAY, SUNDAY -> 6;
        case TUESDAY -> 7;
        default -> {
          String s = day.toString();
          int result = s.length();
          yield result;
        }
    };
  • Definition of var variable to define local variables:
    JDK 11 (Without lambda support in JDK 10)
    var greeting = "Hello World!";
  • Prevent ClassDefNotFoundErrors at runtime and create internal APIs:
    JDK 9
    module hu.advancedweb.helloworld {
        requires hu.advancedweb.somedependency;
        exports hu.advancedweb.hello
    }
  • Define private methods in intefaces. (JDK 9)
  • Try-with-resources allows the use of final variables more effectively. (JDK 9)
  • Use @SafeVargs on private methods. (JDK 9)
  • Removing outdated warnings in imports. (JDK 9)

New APIs:

We want to explore Java libraries by focusing on new features that we can use in our programming.
  • Process::inputReader, Process::outputWritter, Process::errorReader : Functions for managing streams in JDK 17.
  • java.time.InstantSource: An interface that returns the present and is derived from java.time.Clock. (JDK 17)
  • HexFormat: Code functionality and code a string of hexadecimal.
    JDK 17
    HexFormat.of().toHexDigits(123);
    ==> "0000007b"
    HexFormat.of().fromHexDigits("0000007b");
    ==> 123
  • Vector API: To perform calculations that are associated with hardware instructions. (JDK 17)
  • Foreign linker API: to access the native code
  • Foreign memory: Access Java Heap memory. (JDK 17)
  • Align random generators : Improve random functions such as : Random, ThreadLocalRandom, SplittableRandom
    JDK 17
    new Random().ints()
        .limit(10)
        .forEach(System.out::println);
  • Stream.toList: Improve the algorithm of its use.
    JDK 16
    List<String> result =
      Stream.of("one", "two", "three").stream()
        .filter(s -> s.length() == 3)
        .toList();</String>
  • Stream.mapMulti: Improve its use algorithm.
    JDK 16
    Stream.of(1, 2, 3, 4)
        .mapMulti((number, downstream) -> downstream.accept(number))
        .forEach(System.out::print); prints 1234
  • A new builder for handel HTTP’s.
  • DateTimeFormatterBuilder.html #appendDayPeriodText: AM/PM Support
  • Added Unix domain socket channels and server socket channels
  • @Serial: To identify the field or methods that use the serialization mechanism.
  • Files.mismatch: Find the first uncoordinated bytes in two files. (JDK 12)
  • Collectors.teeing: To create a collection that combines two collections downstream. (JDK 12)
  • Strengthen strings: Niche and convert a string. (JDK 12)
  • HTTP Client standard includes HTTP/2, WebSocket support and block-free API:
    JDK 11
    HttpClient httpClient = HttpClient.newBuilder().build();
    
    HttpRequest request =
      HttpRequest.newBuilder()
        .uri(URI.create("https://advancedweb.hu/"))
        . GET()
        .build();
    
    HttpResponse<String> response =
      httpClient.send(request, BodyHandlers.ofString());</String>
  • Strengthen strings : isBlank, lines, repeat and strip .
  • Factory method improvements for collections that do not have subsets.
    JDK 9
    Set<Integer> mySet = Set.of(1, 2, 3);
    List<Integer> myList = List.of(1, 2, 3);
    Map<String, integer=""> myMap = Map.of("one", 1, "two", 2);</String,> </Integer> </Integer>
  • Improve publish-subscribe streams to prevent blocking.
  • Improve time usage such as latency and timeout.
  • Added more features to convert or create collections : dropWhile, takeWhile and iterate, ofNullable
  • Arrays.mismatch: Find the first dissonance between the two arrays.
  • System.Logger: Improve the log mechanism in the system.
  • Stack-Walking API: Possibility to implement lazy mechanism and filter frames.
  • Process API: provides more information and control (e.g. process ID, arguments, CPU time, parent/child processes), enhancing processBuilder to help create new process lines.
  • VarHandle API: To replace operations related to the java.util.concurrent.atomic array and sun.misc. Insecure in order to create and provide low-level access mechanisms, e.g. the use of atomic.
  • New combinators and search methods for MethodHandle
  • Deprecated’s advanced patent policy can be marked with forRemoval, which gives a new warning.

Concurrency :

  • Ability to stop a handShake crisp in JDK 9.
  • Improve monitoring performance in JDK 9.
  • Extra space for a crisp Stack and reduce the risk of deadlock in java.util.concurrent in case of overflow Stack in JDK 9.

Garbage Collector :

  • NUMA-Aware memory allocation in JDK 12.
  • Automatic heap memory release. (JDK 12)
  • G1 Garbage Collector is now set by default instead of Parallel GC. (JDK 9)

Security:

  • Validate serialization data as input (JDK 17).
  • The default keystore instead of proprietary JKS is the standard PKCS12. (JDK 9)
  • SecureRandom drbg-based (JDK 9).
  • X.509 certificate chains are disabled with SHA-1-based signatures. (JDK 9)
  • SHA-3 Hash algorithms (JDK 9).

Run:

  • Support the execution of single-file source codes, including shebang line support (#!) in Unix. (JDK 11)
  • jshell: the Java REPL
  • Compile older projects with –release that are different from new versions. (JDK 9)
  • Initial validation of the JVM command line to prevent crash. (JDK 9)

Support for new platforms:

  • macOS/AArch64 on JDK 17
  • Windows/AArch64 in JDK 16
  • Linux/AArch64 on JDK 9
  • Linux/s390x on JDK 9
  • Unified arm32/arm64 in JDK 9

Obsolete and deleted:

  • Applet API on JDK 17
  • Solaris and SPARC Ports in JDK 14
  • Biased locking in JDK 15
  • Unsafe::d efineAnonymousClass() at JDK 15
  • Concurrent Mark Sweep in JDK 14
  • ParallelScavenge + SerialOld in JDK 14
  • Pack200 Tools and API in JDK 14
  • Java EE in JDK 11
  • CORBA at JDK 11
  • Thread#destroy and Thread#stop in JDK 11
  • javah tool in JDK 10
  • Apple.applescript and com.apple packages in JDK 9
  • X.509 Certificate chains based on SHA-1 in JDK 9
  • jhat tool in JDK 9
  • JVM TI hprof Agent in JDK 9
  • Object.finalize() in JDK 9

And in the end,

JDK 8 was released in 2014. We had to wait three and a half years for JDK 9. But from then on everything accelerated. Java has a new release structure that aims to deliver a new version every six months.

Mirbazorgi’s website aims to help you learn and fix your problems by providing articles and practical experiences. Email me if you have any questions.