Java 20
Java 20 was released on time to the public. The release has been available for download since 21st March 2023.
Interestingly, the new Java release contains only incubating or preview JEP proposals. No final improvements are part of this version.
You are a Java developer, you should always install the latest JDK and try it out. Most of the time, all your products will compile and run on the new release without any changes.
You get new features, performance improvements, and better security for free.
As soon as you have to write code, you will enjoy higher productivity thanks to the new features. Your source code will be quite different from functional equivalent source code written with an older Java version.
The projects Amber, Loom, and Panama provide the improvements provided in JDK 20.
The project Amber provided improvements in pattern matching features.
-
Record Patterns Second Preview
-
Pattern Matching for Switch Fourth Preview
The project Loom provided refinements in virtual threads and structured concurrency.
-
Scoped Values Incubator
-
Virtual Threads Second Preview
-
Structured Concurrency Second Incubator
The project Panama refined the access to functions and data provided by external libraries written in non-JVM languages.
-
Foreign Functions and Memory API Second Preview
-
Vector API Fifth Incubator
Algebraic Types and Pattern Matching
Brian Goetz and his team are adding syntactic sugar constructs to the language. Step by step the algebraic data types with records [5] and sealed types and the pattern matching tools move Java to more complete functional programming approaches.
The sum of small improvements finally empowers us to write more legible source code. The switch expression is an elegant and compact solution for conditional selection.
The next JDK will hopefully again improve the legibility of the code. The proposed improvements are anonymous variables in deconstruction expressions and support of primitive types in switch expressions.
Virtual Threads and Structured Concurrency
Death to complex asynchronous programming and nightly debugging sessions. The structure of the code visualizes the concurrency flow in your application.
The Loom project is the kid on the block. The structured concurrency approach has the promise to tremendously simplify concurrent programming.
Work is under way to provide scoped values and deprecate thread local storage.
I hope that Loom will deliver another promise and give us optimized tail recursion in the near future.
Interfaces to external libraries and memory structures
Java is not an island. We want to interface to external digital systems and powerful libraries.
JNI solution is obsolete. Panama project provides way better approaches to interface with external libraries.
Thoughts
The project amber is a powerful driver for regular Java improvements. The next goodies for JDK LTS 21 should be Sequenced Collections and String Templates. Especially the string templates will simplify quite a few lines of our code.
The tools are also getting better. For example, IntelliJ IDEA and Gradle provide timely updates for newer Java versions
Support for newer features in regular libraries is catastrophic. The Java community emphasizes backward compatibility and sacrifices elegance [2].
Seminal works [1, 2] provides examples how to write modern and expressive Java code. Cool products [1] allow the creation of digital products and user interfaces using only the Java stack.
An introductory book [3] helps newcomers to the Java language.
The diagram shows the hot topics in the Java ecosystem. The adoption takes time before a majority of development organizations jump on the train.
The adoption of the Java 17 LTS edition is still in the early adoption phase after two years, as stated in the below diagram.
We should rather state that the majority of Java teams are laggards, also called more politely late majority.
Links
-
[1] Vaadin. Marcel Baumann. 2022.
-
[2] Java 17. Marcel Baumann. 2021.
-
[3] Java 16. Marcel Baumann. 2021.
-
[4] Java 10 aka 18.3 Changes. Marcel Baumann. 2018.
-
[5] Immutability in Java. Marcel Baumann. 2022.
-
[6] Modern Java Constructs. Marcel Baumann. 2022
-
[7] Modern Java Development. Marcel Baumann. 2021.
References
[1] J. Bloch, Effective Java, Third. Addison-Wesley Professional, 2017 [Online]. Available: https://www.amazon.com/dp/B078H61SCH
[2] V. Subramaniam, Functional Programming In Java Harnessing The Power Of Java 8 Lambda Expressions. The Pragmatic Programmers, 2014 [Online]. Available: https://www.amazon.com/dp/B0CJL7VKFL
[3] S. Harrer, J. Lenhard, and L. Dietz, Java By Comparison. Pragmatic Bookshelf, 2018 [Online]. Available: https://www.amazon.com/dp/B07CLFTVZS