What are the new features of java-14?
On March 2020, Oracle released a new version of Java as Java-14. Following are the new features of java-14.
Switch Expressions
- This feature was part of the preview feature in java-12 and java-12. In this version of Java, we can actually use this feature and do coding wherever required
- Before checking what is newly updated in Switch statements we will see the old code for the same.
- As a part of Java-14, we can now modify the above code as shown below.
- As we can see in the above example, the new switch expression is more compact and readable.
- There is also no need to add the break statement after the end of the case.
- We can assign this switch statement directly to the variable as shown in the below image.
- We can warp complex logic into curly braces as shown in the below image.
Helpful NullPointerException:
- For the below code where the value of the string str is null.
- Before the java-14 version, we will get the below generic NullPointerException.
- From java-14 onwards we will get the NullPointerExceptions as follows, which will also inform us about the null object with reason.
Foreign-Memory Access API
- This API allows the Java program to access foreign memory, such as native memory, persistent memory, managed heap memory, etc.
- The foreign-memory access API introduces three main abstractions: MemorySegment, MemoryAddress, and MemoryLayout.
- A MemorySegment is used to model a contiguous memory region with given spatial and temporal bounds. A MemoryAddress can be thought of as an offset within a segment. Finally, a MemoryLayout is a programmatic description of a memory segment’s contents.
Packaging Tool
- This creates a tool for packaging self-contained Java applications based on the JavaFX java-packager tool, that:
- Supports native packaging formats to give end users a natural installation experience. These formats include msi and exe on Windows, pkg and dmg on macOS, and deb and rpm on Linux.
- Allows launch-time parameters to be specified at packaging time.
- Can be invoked directly, from the command line, or programmatically, via the ToolProvider API.
NUMA(Non-Uniform Memory Access)-Aware Memory Allocation for G1
- To improve G1 performance on large machines by implementing NUMA-aware memory allocation
Also, see:
- New features of Java-8
- New features of Java-9
- New features of Java-10
- New features of Java-11
- New features of Java-12
- New features of Java-13