Monday, January 11, 2021

Top 10 JDK 10 Features Java Developers Should Learn in 2024

Hello Guys,  last week I wrote an article about 5 New Java features from Java 9 to Java 15 and which are worth learning in 2024, and it was very much liked by you, so I thought to update this article which I wrote when JDK 10 came out, which provides a nice overview of essential Java 10 features. Whether you have no idea about Java 10 features or you know a little bit you can use this article to refresh your knowledge or get a nice overview of them. While we all are talking about Java 9 and some people are yet to adopt Java 8 in their projects, here comes the new release of Java, the JDK 10. It's available to download now on Oracle's website. 

This is the first release in the latest release schedule, where you have a new Java release every six months, I know it's quite early, but that's a reality now. 

Apart from the 6 monthly releases, Every 3 years there is an LTS release, which is a sort of a major Java release. The next LTS release is Java 21 which should be out in September 2024. So you can aim for that. Then you can update three years after that to the next LTS release.


10  Java 10 Features Developer Should Know

Even though JDK 10 looks come really quick, there are some interesting features coming in JDK 10. I have yet to go into the details of that but on prima-facia they look useful and interesting to me.

Here is a quick note on those new Java 10 features:

1. Local Variable Type Inference (JEP 286)

Similar to Javascript, Kotlin, and Scala, now Java will also have a var keyword that allows you to declare a local variable without specifying its type. The type will be inferred from context for example when you say var name = "Java" then compile will already know the type is String.

I don't know how useful this will be as I am quite used to seeing int i =0 or String name = "Java" and I liked the type information present in the variable declaration line but looks like Java is going the way Scala and Kotlin are and trying to incorporate changes from there.

Also, note that the var keyword can only be used for local variables i.e. variables inside methods or code blocks, you cannot use it for member variable declaration inside the class body.

And, finally, it doesn't make Java a dynamically typed language like Python, Java is still a statically typed language and once the type is assigned you cannot change it. For example, var name = "Java" is ok but then name = 3; is not ok.

As Sander Mak puts in his Pluralsight course What's New in Java 10 this is one of the most eye-catching features of Java 10 which reduces the amount of boilerplate code needed to declare local variables in Java.

It's not so obvious from a simple example but considers where a method returns a complex list type which requires a  lot of angle brackets and generics to declare the type, this really saves time in those case:

var list = List.of(1, 2.0, "3")

Here list will be inferred as List<? extends Serializable & Comparable<..>> which is an intersection type. You can also learn more about Java 10 features on The Complete Java MasterClass course on Udemy, which is the most comprehensive resource and also updated for Java 10.

A quick overview of var feature from Java 10


2. Time-Based Release Versioning (JEP 322)

From JDK 10 release, Java has adopted a new schedule of a new release every six months. There is a lot of debate whether this is a practical approach or not as many are saying that it's good that you will get new features every six months and many are complaining that it's too little a time to adopt a JDK.

Anyway, this will be the way forward with an LTS release every three years, consider that a major release.

Also, The Update element will increment one month after the Feature element is incremented so the April 2018 Java release will be JDK 10.0.1, July 2018 release will be named JDK 10.0.2, and so on.

10 New JDK 10 Features Java Developers Should Know



3. Garbage-Collector Interface (JEP 304)

This is one more interesting and useful Java 10 feature that increases the code isolation of different garbage collectors and introduces a clean interface for garbage collectors.

This means it easier to exclude a GC from a JDK build and it also easier to add a new GC without it affecting the codebase.  You can further see the Java Memory Management course to Udemylearn more about G1 Garbage Collection and the difference between G1 and Concurrent Mark Sweep Garbage Collectors.




4. Parallel Full GC for G1 (JEP 307)

Another interesting feature that improves G1 worst-case latencies by making the full GC parallel.

If you remember, In Java 9 release, G1 was made the default GC for JVM, which was designed to avoid full GC, but when the concurrent collections couldn’t reclaim memory quick enough it would end up falling back on a full GC, and that creates a problem.

This change will parallelize the full GC algorithm so that in the unlikely event of a G1 Full GC, the same number of threads can be used as in the concurrent collections to improve the overall performance.

If you want to learn more about Parallel Full GC for G1 then you should watch What's New in Java 10 by Sander Mak to learn about the performance improvement done on Java 10 release. He has nicely put together some important JDK features in a short course on Pluralsight.

Overview of New Features of Java 10




5. Heap Allocation on Alternative Memory Devices (JEP 316)

This sounds like a really cool feature that enables the HotSpot VM to allocate the Java object heap on an alternative memory device, specified by the user.

For example, this feature makes it possible to assign lower priority processes to use the NV-DIMM memory, and instead only allocate the higher priority processes to the DRAM in a multi-JVM environment.

Btw, If you don't know much about JVM, I suggest you first start with Understanding the Java Virtual Machine: Memory Management By Kevin Jones, a good introductory course on JVM.




6. Consolidate the JDK Forest into a Single Repository (JEP 296)

This new Java 10 feature is all about housekeeping. It will combine the numerous repositories of the JDK forest into a single repository.




7. Root Certificates (JEP 319)

This is another important change Java 10 is bringing. If you remember, JDK 10 was created with close collaboration with OpenJDK and this is evident from this feature.

It will provide a default set of root Certification Authority making OpenJDK builds more appealing to developers.

It also aims to reduce the difference between the OpenJDK and Oracle JDK builds. Critical security components such as TLS will now work by default in OpenJDK builds




8. Experimental Java-Based JIT Compiler (JEP 317)

This is another interesting feature that enables the Java-based JIT compiler, Graal, to be used as an experimental JIT compiler on the Linux/x64 platform.

If you remember, Graal was already added back in Java 9, but now you can enable it with the following JVM arguments:

-XX:+UnlockExperimentalVMOptions -XX:+UseJVMCICompiler

If you don't know Grall is a new Java-based JIT compiler which is the basis of an experimental Ahead-of-Time (AOT) compiler.

However, keep in mind that it is in an experimental stage and you should not use it for production.





9. Thread-Local Handshakes (JEP 312)

This Java 10 feature lays the groundwork for improved VM performance, by making it possible to execute a callback on application threads without performing a global VM savepoint. This would mean that the JVM could stop individual threads and not just all of them.

There are several small improvements done as part of this feature or JEP 312 to improve VM performance e.g. some memory barriers have been removed from the JVM and biased locking is improved by only stopping individual threads for revoking biases.


10. Remove the Native-Header Generation Tool (JEP 313)

This is another Java 10 feature that focuses on housekeeping. It will remove the javah tool from the JDK, a separate tool to generate header files when compiling JNI code, as this can be done through javac.

You can download JDK 10 from Oracle's website here to play with the new features:

Java 10 Released - 10 New Features Java Developer Should Know


That's all about some interesting features of Java 10 or JDK 10. There are a lot more low-level and API changes which you can find on Oracle's official release notes. I'll also blog about those changes as and when I come to know about them, so you can stay tuned for more JDK 10 articles and tutorials here in Javarevisited.

Other Useful Resources for Java Programmers

Thanks for reading this article so far. If you like these Java 10 features then please share with your friends and colleagues. If you have any questions or feedback then please drop a note.

All the best with JDK 10

P. S. - If you want to learn Java from scratch and looking for some recommendations, you can also check my post about the top 5 Java courses for beginners. It contains some of the best Java courses from Udemy, Pluralsight, and Coursera to kickstart your Java journey.

5 comments :

Anonymous said...

Interesting features but I agree 6 month release cycle is very aggressive for anyone to adopt.

Javin said...

Another useful feature to add into this list Application Class Data Sharing as rightly pointed out by Nicolai Parlog on twitter. This was a feature which was earlier available to commercial JVM but no its available to open JDK and can significantly improve application launch time. He has also blogged about it on his blog and you can read it for more details https://blog.codefx.org/java/application-class-data-sharing/

Unknown said...

Hi Javin...
Earlier there was an option to see the index of all your posts year and month wise.(tree structure) at the right side of the blogs. Now that option is not showing. Is there any way/index to browse across all your blogs?

Javin said...

Hello Unknown,

I have removed that option for now but will add it back as some other readers has also requested that.

Thanks
Javin

Javin said...

Hello guys,

Here is another useful link to effectively use the var or local variable type inference in Java 10 code:

Style Guidelines for Local Variable Type Inference in Java
http://openjdk.java.net/projects/amber/LVTIstyle.html

A good read to understand how using var can reduce noise and improve code quality.

Post a Comment