Java 11, all the news

0
349

We discover all the new features of the Java 11 Long Term Support (LTS), from licensing changes to new functionalities integrated into the language.

Starting with version 9, Oracle’s policy has been to release Java updates every six months. The release of new versions is planned for the months of March and September each year. With this article we introduce the release 11 offered by Oracle starting from September 2018.

The first aspect to underline is the type of release that Java 11 represents, it is in fact a LTS ( Long-Term Support ), this indicates the possibility of receiving updates for a period of at least eight years . The LTS license offers updates with performance, stability and security certified and guaranteed directly by Oracle. Users who want to have a continuous access to new improvements can orient themselves on the releases of the OpenJDK versions.

Oracle will provide the JDK version either through the GNU GPL v2 license with the Classpath Exception (GPLv2 + CPE) or the commercial one for the use of JDK as part of an Oracle product or service. This combination, Open Source + Commercial replaces the historic BCL. The JDK under BCL did not generally contain features present in the commercial, the change therefore determines that the JDK version of Oracle and the OpenJDK will be essentially similar and in the Open version we will have:

ZGC: Scalable Low-Latency Garbage Collector.
Lazy Allocation of Compiler Threads.
Epsilon GC.

ZGC: Scalable Low-Latency Garbage Collector

ZGC is the abbreviation for the Z Garbage Collector, a scalable low-latency garbage collector designed to achieve a waiting time of no more than 10 ms and for managing a HEAP memory ranging from hundreds of Mb to different Tb. The ZGC is a concurrent garbage collector, which means that the bulk of its work is done with Java threads that continue their execution.

This behavior greatly limits the negative impact that the grabage collection can have on the response times of the applications.

<pre class=”brush: php; html-script: true”>
-XX:+UseDynamicNumberOfCompilerThreads
</pre>

Epsilon GC

Epsilon GC is an experimental no-op garbage collector, it manages only the memory allocation not implementing any mechanism of recovery of the same. Its use is particularly useful for performing performance tests in order to evaluate the costs and benefits of different implementations of the Garbage Collectors or, in extreme cases, for use with particularly short life Jobs where the memory recovery phase coincides with the termination of the JVM.

Changes to the language

The changes that directly affect the language go to improve and complete aspects already introduced by version 10. For example with Java 10 the introduction of the keyword varhas inserted in the automatic type inference of the type leading to the writing of a more compact code. In the following code fragment

<pre class=”brush: php; html-script: true”>
var mioTesto = “Ciao Java 11″;
</pre>

the compiler deduces the type of the variable based on the assigned value, in this case a string. The limitation of Java 10 prevented its use within Lambda expressions and was removed bringing benefits not so much in terms of a less verbose code, as for the possibility of using annotations for the parameters of a Lambda expression:

<pre class=”brush: php; html-script: true”>
Predicate<String> mioPredicato = (@Nullable var myVar) -> true;
</pre>

With Java 9 we saw the introduction of the HttpClient API as an incubating feature, Java 11 completes these APIs making them available in the package <code>java.net</code>. The class <code>Stream</code> is provided with three new methods:, <code>ofNullable()</code> which allows to obtain a stream from a single element, <code>dropWhile()</code> and <code>takeWhile()</code> which can receive a predicate to determine which elements to abandon of a stream:

<pre class=”brush: php; html-script: true”>
Stream.ofNullable(null).count();
Stream.of(1, 2, 3).dropWhile(n -> n < 2).collect(Collectors.toList());
Stream.of(1, 2, 3).takeWhile(n -> n < 2).collect(Collectors.toList());
</pre>

Finally, very interesting are the methods that enrich the class <code>String</code> and allow an easy test on empty strings, elimination of space at the beginning or end of the string and counting lines:

<pre class=”brush: php; html-script: true”>
” “.isBlank(); // true
” Testo1 Testo2 “.strip(); // “Test1 Test2″
” Testo1 Testo2 “.stripTrailing(); // ” Test1 Test2″
” Testo1 Testo2 “.stripLeading(); // “Test1 Test2 ”
“Testo1”.repeat(3); // “Test1 Test1 Test1”
“Testo1\nTesto1\nTesto1”.lines().count(); // 3
</pre>

LEAVE A REPLY

Please enter your comment!
Please enter your name here