/poc-java-14

This is a simple poc using the new version o Java language

Primary LanguageJavaApache License 2.0Apache-2.0

Overview

The Java 14 was release at 03/2020 and the main features are:

"Currency format instances with accounting style, in which the amount is formatted in parentheses in some locales, can be obtained by calling NumberFormat.getCurrencyInstance(Locale) with the "u-cf-account" Unicode locale extension. For example in Locale.US, it will format to "($3.27)" instead of "-$3.27". Refer to CLDR's accounting currency format style for additional information."

In JDK 14, the Records (JEP 359) preview feature adds a new class java.lang.Record. The java.lang package is implicitly imported on demand, that is, import java.lang.. If code in an existing source file imports some other package on demand, for example, import com.myapp.;, and that other package declares a type called Record, then code in the existing source file which refers to that type will not compile without change. To make the code compile, import the other package's Record type using a single-type import, for example, import com.myapp.Record;.

Compiling and running

To compile you need to enable the preview feature, to do that, execute the command bellow:

javac --enable-preview --release 14 src/main/java/com/example/RecordPerson.java src/main/java/com/example/RecordMain.java

To test your application use need to run the command bellow:

java --enable-preview -cp src/main/* com.example.RecordMain

Enhance the Java programming language with pattern matching for the instanceof operator. Pattern matching allows common logic in a program, namely the conditional extraction of components from objects, to be expressed more concisely and safely. This is a preview language feature in JDK 14.

Compiling and running

To compile you need to enable the preview feature, to do that, execute the command bellow:

javac --enable-preview --release 14 src/main/java/com/example/PatternMatching.java

To test your application use need to run the command bellow:

java --enable-preview -cp src/main/* com.example.PatternMatching

Create a tool for packaging self-contained Java applications.

Packing and running

To package your application, run the command bellow:

jpackage --name poc-java-14 --input target/ --main-jar poc-java-14-1.0-SNAPSHOT.jar --main-class com.example.PatternMatching

To run your application, execute the generated file poc-java-14* at your root folder:

  • Linux: deb and rpm
  • macOS: pkg and dmg
  • Windows: msi and exe

Improve the usability of NullPointerExceptions generated by the JVM by describing precisely which variable was null.

Extend switch so it 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 no fall through), with a further new statement for yielding a value from a switch expression. These changes will simplify everyday coding, and prepare the way for the use of pattern matching in switch. This was a preview language feature in JDK 12 and JDK 13.

Add text blocks to the Java language. A text block is a multi-line string literal that avoids the need for most escape sequences, automatically formats the string in a predictable way, and gives the developer control over the format when desired. This is a preview language feature in JDK 14.