Skip to content
Sandny Blog
  • Home
  • Java
  • JavaScript
  • AWS
  • Embedded
  • About
The new features in Java 14 Java

JDK 14 – The new features in Java 14

  • December 27, 2019December 27, 2019
  • by Coder Kai

Recently, Java changed its release cycle more rapidly. JDK 13 released on September 2019 and JDK 14 is scheduled for a production release on 17 March 2020. The features targeted to JDK 14 as follows,

1. Pattern Matching for instanceof

Java instanceof operator is used to test whether the object is an instance of the specified type. With Java 14 instanceof operator enhance to the pattern matching as bellow,

Before Java 14;

// need to declare and cast again the object
if (obj instanceof String) {
    String str = (String) obj;
    str.contains(..) 
}

With Java 14;

// no need to declare str object again with casting
if (!(obj instanceof String str)) {
   str.contains(..);
}

2. Helpful NullPointerExceptions

Referance – JEP 358: Helpful NullPointerExceptions

With java 14 improve the usability of NullPointerExceptions generated by the JVM by describing precisely which variable was null. It will print the The JVM will print out the method, filename, and line number that caused the NullPointerException.

Exception in thread "method" java.lang.NullPointerException at Filename.method(linenumber)

The NullPointerExceptions error message may contain variable names from the source code. This can expose the security risk.

3. Switch Expressions (Standard)

Switch can be used as either a statement or an expression, and so that both forms can use either traditional case … : labels (with fall through) or new case … -> labels, with a further new statement for yielding value from a switch expression. This was a preview language feature in JDK 12 and JDK 13 and become permanent in JDK 14.

Example

switch (day) {
    case MONDAY, FRIDAY, SUNDAY -> System.out.println(6);
    case TUESDAY                -> System.out.println(7);
    case THURSDAY, SATURDAY     -> System.out.println(8);
    case WEDNESDAY              -> System.out.println(9);
}

4. Non-Volatile Mapped Byte Buffers

JDK 14 include new JDK-specific file mapping modes so that the FileChannel API can be used to create MappedByteBuffer instances that refer to non-volatile memory.

This JEP makes use of two related enhancements :

1. Support implementation-defined Map Modes (JDK-8221397)

2.MappedByteBuffer::force method to specify range (JDK-8221696)

4. Flight Recorder Event Streaming ( JFR Event Streaming ) for Continuous Monitoring

This will provides an API for the continuous consumption of JFR data from both in-process and out-of-process applications. And record the same set of events as in the non-streaming case, with overhead less than 1% and streaming must be able to co-exist with non-streaming recordings, both disk and memory-based.

But there can be risks in API callbacks may provoke JFR events, which could lead to infinite recursion. This can be mitigated by not recording events in such a situation.

Java 13 extends the previous Java 12 Switch Expressions by adding a new yield keyword to return a value from switch expression and breaks syntax is no longer compiled in Java 13, it uses yield instead.

6. NUMA-Aware Memory Allocation for G1

This is a garbage collector, intended to improve G1 performance on large machines. 

7. Packaging Tool (Incubator)

This is a tool for packaging self-contained Java applications into a platform-specific package that includes all of the necessary dependencies. The application may be provided as a collection of ordinary JAR files or as a collection of modules. The supported platform-specific package formats of Linux (deb and rpm ), macOS( pkg and dmg) and Windows (msi and exe).

Other features will be introduced in JDK 14 are Deprecate the Solaris and SPARC Ports, Remove the Concurrent Mark Sweep (CMS) Garbage Collector, ZGC on macOS, ZGC on Windows, Deprecate the ParallelScavenge + SerialOld GC Combination, Remove the Pack200 Tools and API, Text Blocks (Second Preview), Foreign-Memory Access API.

Related Articles

  • Java 13 features
  • Java 13 Switch Expression
AndroidX ClassNotFound Exception: “android.support. v4.content .FileProvider”
Android/iOS React-native heap limit allocation failed error
Coder Kai
A humble developer
Java 14

Related articles

String.lines()
How to convert a string…
How to avoid NullPointerException in Java
How to avoid NullPointerException in…
Java 13 features
Java 13 (JDK 13) -The…
Java 13 Switch Expressions
How to enable preview feature in Java 13 with maven.
Enable the Preview Feature in…
create a Vertx Eventbus js client
How to create a Vertx…
neo4j boltdriver
How to create a neo4j…
Servlet File Upload
Servlet File Upload
Java RMI Slider
JAVA RMI Observer Slider

Categories

  • android 3
  • Apollo Client 1
  • AWS 8
    • AppSync 5
    • EC2 1
    • EKS 1
    • Route53 1
    • S3 1
  • AWS Amplify 1
  • Chakra UI 1
  • Docker 1
  • Embedded 1
  • EmberJS 1
  • FCM 1
  • Godaddy 1
  • GraphQL 3
  • ios 1
  • Jasper 1
  • Java 10
    • Java 11 1
    • Java 14 1
  • JavaEE 2
  • JavaScript 39
    • Express.js 4
    • Javascript Guide 7
    • Node.js 3
    • react-native 4
    • React.js 17
    • Typescript 1
  • Kubernetes 1
  • machine learning 1
  • Maven 2
  • OCaml 3
  • PostgreSQL 1
  • Python 2
  • react-native 4
  • ReactJS 3
  • sass 1
  • Server 6
  • spark 1
  • Terraform 2
  • Ubuntu 4
  • Uncategorized 1
  • webpack 2

Recent Comments

  • binance Registrera dig on Higher order component wrappers using React.js and reusable components.
  • kopya site buyhacklink.com on How to create Lambda function with Terraform
  • Pamela587 on Chakra UI Animations

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Archives

  • October 2022 3
  • September 2022 7
  • May 2022 1
  • December 2021 1
  • August 2021 1
  • July 2021 6
  • June 2021 3
  • February 2021 1
  • July 2020 1
  • December 2019 5
  • November 2019 6
  • October 2019 3
  • August 2019 1
  • March 2019 1
  • February 2019 1
  • January 2019 2
  • December 2018 1
  • September 2018 2
  • August 2018 1
  • June 2018 1
  • February 2018 1
  • November 2017 2
  • October 2017 5
  • September 2017 1
  • June 2017 1
  • May 2017 10
Sandny Blog space
Theme by Colorlib Powered by WordPress