Java has been around more than 20 years and has been declared dead by critics numerous times. They have kept the language alive by staying relevant to problems and hardware. The faster release cycle allows the Java team to work on good small features. It also helps laying the groundwork for future releases. Preview features help in risk reduction by gathering feedback. There are various projects in the works that will allow Java to adapt to higher expectations of the developers, bring value types, generic specialization, and better interoperability with native code.
Switch and pattern matching
He goes over the new switch statements in Java 12 with an example. The new expression switch simplifies the code a lot, by allowing not just lesser typing but also makes the code less error prone. Switch expressions is a part of a larger concept called pattern matching. It combines a test, a conditional extraction and a binding into one operation. The code looks cleaner with pattern matching as it eliminates redundant boilerplate.
The goal of this project is to reboot the way JVM lays out data in memory. The hardware has changed drastically in the last three decades. The cost of memory fetch versus arithmetic has increased hundreds of times. Memory efficiency is lost in between this increased cost. Alternatives like stuffing data into arrays under a single header makes the code worse. This project introduces value types that ‘codes like a class, works like an int’.
Project Valhalla has been running for the past 5 years and has different phases. The current prototype is called LW1 and has the VM underpinnings validated. The next prototype called LW2 out next year should be good for experimentation.
Project metropolis is also in the early stages. It’s about replacing the C2 compiler with the Graal compiler.
The Java team is working on a lot of features across various categories such as language productivity features, fundamental VM performance features, native interop, concurrency models etc,. They are starting to be better formed now after years of work through various projects. The bi-yearly releases help test more features than before and the limited LTS releases would help the core developers to work with better focus. Project Valhalla seems promising and could possible make Java much more memory efficient.
To see code demo and explanation with QnA, you can watch the talk.