Java/JDK 16 is short term support release of highly popular Java programming language. In this tutorial we are going to learn the features of Java 16.Java/JDK 16 is short term support release of highly popular Java programming language. In this tutorial we are going to learn the features of Java 16.
Java 16 is released on March 16th as short term support product and the support will end once long-term supported JDK 17 is released in November 2021. Java 16 is released with many new features and updates to the Java project. Developer should learn and understand the features that is coming with Java 19.
In this article we are going to explain you all the features of Java/JDK 16. Java 16 comes with lots of new features and update which give more tools in the hand of Java developers. The features in the Java 16 includes primitive classes, sealed classes, records, vector API and it is ported to Windows ARM 64 and Alpine Linux.
Now Oracle JDK 16 and OpenJDK 16 is available for production use, which can be downloaded and installed from respective websites. This release of JDK 16 brings second preview of sealed classes and many others. The JDK 16 is reference implementation of Java 16 and it follows the JDK 15, which was released in September last year. The JDK 16 is short term supported of JDK and its support will end once JDK 17 is released. The JDK 17 is expected to be released in September 2021 and it will be long-term supported JDK version. The JDK 17 will be called as JDK 17 LTS, where LTS means Long Term Support. The LTS version is released every 3 years.
Now let's see all the new and update features of Java/JDK 16, which is released in March 20201 and it is released under short term support.
Java 16 introduced Vector API (Incubator) which will allow the developers to perform the vector operations using the Vectors in Java programming language. This will greatly increase the parallelism during vector processing. Java 16 Vector API provides the functionality to perform the vector computational operations on the vectors. It will help in significance performance gain while performing such operations on the CPU as vector operations can be executed in parallel.
The limited C++14 feature was enabled in JDK 15 and now in JDK 16 more C++14 language features are enabled. In the JDK 16 the C++ 14 features are enabled which means code is compiled with std=c++14 like options for Windows, Linux, macOS and AIX. This will enable the Java to take standard c++ 14 features to take the advantages of c++ 14 features.
The source code of OpenJDK is migrated from Mercurial to the Git repository. It preserves all the version control history and tags. So, its a good move by the OpenJDK team.
Source code of JDK is finally migrated to the GitHub public repository, now developers will be able to see the Java source code on the public Git repository.
In JDK 16 the thread-stack processing is moved from ZGC safepoints to a concurrent phase. This will make stack processing lazy, cooperative, concurrent and incremental.
Java 16 enables Unix-Domain Socket Channels for internal IPC within the same system. This will further performance boost to the Java applications developed in Java programming language. The SocketChannel and ServerSocketChannel API in Java is used for develop communication applications using socket for data transfer. This API provides the functionality to develop the application for blocking and multiplexed non-blocking access to TCP/IP sockets in Java.
Java and JDK 16 is now ported to Alpine Linux, as you know Alpine Linux is very popular for cloud deployment and webservices deployment. The Docker image of this Linux is very small and it's size is just 6MB. This Linux can be used for running Tomcat, Jetty and other Java applications.
The Elastic Metaspace feature is added to Java 16 which is returns the unused HotSpot class-metadata memory to the operating system more promptly. This helps in reducing the metaspace footprint and helps in reducing the maintenance costs.
The Java/JDK 16 is now compiled for Windows/AArch64 to meet the growth in Windows/AArch64 based servers. These days new consumer and server devices is being developed using AArch64 (ARM64) architecture and this port of JDK will enable the users in running Java applications on these devices.
The Foreign Linker API (Incubator) has been introduced in Java 16, which allows to access the to the native code purely in Java.
In the JDK 16 primitive wrapper classes have been placed as value-based and deprecated the constructors for future removal. The new deprecation warnings is also added in Java 16 for these classes.
In Java 16 a packaging tool called jpackage is added which enables the developers to create Java installable package for distributing their applications. It comes with the platform specific packages for Linux, macOS and Windows, which enables the installable package in platform dependent format. This is a good edition to the Java 16, which will allow developers to create and distribute installable package of their applications.
Java 16 added Foreign-Memory Access API (Third Incubator) API which will enable Java applications to safely and efficiently access the memory outside of Java heap. This single API is able to access various kinds of foreign memory (e.g., native memory, persistent memory, managed heap memory, etc.) from Java program.
Java 16 brings pattern matching for instanceof, which will help Java programmers in writing much better program.
Earlier in JDK 14 and 15 Records were released as preview feature, now in JDK its no longer preview and its released as production ready version in JDK 16. The Records feature is said to be the most favoured feature of JDK 16. As per the JEP 395 "Records are a new kind of class in the Java language. They act as transparent carriers for immutable data with less ceremony than normal classes. Records can be thought of a nominal tuples."
In Java 16 the internal elements of JDK is now strongly
encapsulated, except critical internal APIs such as sun.misc.Unsafe. If you are
able to compile the code successfully in previous versions of JDK then in this
version of JDK you won't be able to compile. The encapsulation of internal API
was first done in JDK 9 and it was displaying the warning message till JDK 15.
Now, in JDK it is denied and you won't be able to use the JDK Internal APIs by
default. This change was done aiming to encourage developers to migrate their
code to use Java API's rather than internal api. The use of Java API in
application will help in quick upgrade to newer JDK without compatibility
The Sealed Classes (Second Preview) in available in JDK 16, but it is available in the second preview state. This feature restricts other classes or interfaces from being extended or implemented. This feature allows the author of class or interface to control the classes which can implement it. It provides more feature and functionality to restrict the use of classes.
In this tutorial we have learned the features introduced with the Java/JDK 16, after understanding all these features you will be able to use JDK 16 for better application development.
Here are more tutorials of Java/JDK: