What are the key features of Java 9 and 10 that developers should know?

  • Context: Java 
  • Thread starter Thread starter QuantumQuest
  • Start date Start date
  • Tags Tags
    Java
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 replies · 2K views
Messages
928
Reaction score
481
It is about five months since Java 9 was released (JDK 9.0.1 October 17, 2017) and while developers and other users of Java try to keep up to pace with its new features - while others are just adopting Java 8, Java 10 is out! So, I thought that it would be useful for anyone developing / using / interested in Java language and is not aware of those latest releases to briefly review some important Java 9 features and refer to some interesting new features of Java 10.

Java 9 brought a lot of new features and improvements in already existent features. Some of the important ones are

- Java 9 Module System. That was a really big change. As part of the Jigsaw Project Oracle introduced
Modular JDK, Java Platform Module System, Modular Java Source Code, Modular Run-time Images, Encapsulation of Java Internal APIs. The Java 9 Module System was introduced to mitigate the shortcomings of the monolithic way JAR files of Java applications were developed in the past.

- jshell (a.k.a REPL(Read Evaluate Print Loop)) . It is used for easy testing and execution of various Java constructs like class, object, interface etc.

- Private methods in interfaces. From Java 9 on we can utilize private and private static methods in interfaces.

- try-with-resources statement improvement. Although this construct was introduced in Java SE7 there are improvements in Java 9 version regarding verbosity and readability.

- Reactive Streams. As reactive programming has become popular (Scala, Play etc.) Oracle introduced Reactive Streams API. It works in a publish / subscribe fashion and is used to implement Asynchronous, Scalable and Parallel applications in Java.

- Diamond Operator for Anonymous inner classes. The Diamond Operator was introduced in Java SE 7 and it was extended in Java 9 to cover Anonymous inner classes as well.

- java.util.Stream improvement. Three new methods added namely takeWhile(), dropWhile() and ofNullable(). Also the iterate() method was improved in order to solve the problem of non-stopping iteration.

- HTTP2 Client. Java 9 introduced support for HTTP2 protocol and WebSocket.

- There are other various features like Compact Strings, GC improvements, HTML5 Doc etc.

For what's new in Oracle JDK 9 in detail see Oracle's official page

Now, for Java 10 some important features are

- Time-based release versioning . With the introduction of Java 10 a new release cadence has been adopted: six months. Now, this feature although highly debatable among Java developers regarding its usefulness it is what will be followed. There will be LTS (Long Term Support) versions every three years.
For more see JEP 322

- Local Variable Type Inference. As a web developer for some long time I found this feature particularly interesting as it reminds me of JavaScript even in a very limited way. So, Java 10 gives the power of declaring a local variable without specifying its type which is inferred from context. The "local" word was put in italics because Java allows only that. This doesn't make it a dynamically typed language in any way:
The type inferred from context the first time sticks. For more see JEP 286

- Garbage Collector (GC) Interface and Parallel Full GC for G1. The first means an easier way to exclude a GC from a JDK build or adding a new GC without affecting the code base. The second improves overall performance in concurrent collections by parallelizing the full GC with G1 Garbage Collector which was introduced in Java 9. For more see JEP 304 and JEP 307

- Heap Allocation on Alternative Memory Devices. This gives the ability to the VM to allocate object heap on a memory device specified by the user. For more see JEP 316

- Experimental Java-Based JIT Compiler. In Java 9 Graal JIT Compiler was added. Now, in Java 10 it can be used as an experimental compiler on Linux / x64 platform. For more see JEP 317

- Thread-Local Handshakes. Introduces a way to execute a callback on threads without performing a global VM safepoint. Make it both possible and cheap to stop individual threads and not just all threads or none. For more see JEP 312

These are just some interesting new features / improvements in Java 10. For more about it in detail see Oracle's official page.

Sources:

Oracle Corporation Java Documentation
OpenJDK
 
  • Like
Likes   Reactions: Greg Bernhardt
on Phys.org