Top Java 11 Features

11 New Features of Java 11

At an interval of every six months, Java introduces a new version release. On September 25, 2018, Oracle made JDK (Java Development Kit) 11 generally available. The JDK 11 is the latest update of the reference implementation of the Java SE platform and the most effective one in the Java version history. Java SE 11 is also the first Long Term Support (LTS) update in the new six-month release schedule of Java.

Many enthusiasts in the tech world were eagerly waiting for the new release and a look into the latest Java 11 features. The Java 11 comes as the second LTS release after Java 8, speaking enough for its importance. With the launch of Java 11, Oracle JDK is not available anymore for commercial use without any costs. Also, it should be noted that the validity of a Java programming certification is not affected by the new releases.

Check Now: Oracle Java Certification Training Courses

You can use Java 11 at different stages of development. However, commercial use of Java 11 new features would require a license. After the Java 11 release date, many important details came to the front. For instance, Oracle would not provide support for Java 8 after January 2019. You can continue to use Java 8 by paying for support. However, you would not receive any type of patches or security updates.

As you cannot use Oracle JDK any longer without any costs, you could download Open JDK builds. Many providers such as Red Hat, AdoptOpen JDK, IBM, Azul, and others provide flexible options in this regard. You could use Open JDK builds from these providers and also choose to upgrade them when required. Now, let us dive into a discussion on Java 11 new features for understanding what Java 11 brings to the table!

Understanding the New Java 11 Features

Before we take an overview of new Java 11 features with examples, let us look at the important changes first. No deployment stack is ideal for running applets and web applications. Unavailability of deployment stack also involves removal of a complete section of supported browsers from list of supported configurations. Java 11 presents Java Mission Control and JavaFX as separate downloads. There is no auto-update for JRE installations on macOS and Windows.

Java 11 also excludes JRE or Server JRE, and users get only JDK. Java language translation for certain languages is unavailable in Java 11. The languages include French, Italian, Swedish, German, Spanish, Brazilian, Portuguese and Korean. Java 11 features also include changes in updated packaging format for Windows and macOS. The updated packaging format for Windows in Java 11 is .zip rather than tar.gz. The updated packaging format for macOS is .dmg rather than .app. So, let’s move to a detailed overview of the new Java features.

Preparing to become an Oracle Certified Java SE 11 Developer? Check out the preparation guides for Java SE 11 Programmer I 1Z0-815 and Java SE 11 Programmer II 1Z0-816 exams to give your preparation a new edge.

1. Type Inference for Lambda Parameters

The first mention among the latest Java 11 features with examples is type inference for lambda parameters. Now, you can choose to specify types of lambda parameters or omitting them when writing a lambda expression. The example can be shown as follows.

Function<String, String> append = string -> string + " ";

Function<String, String> append = (String s) -> s + " ";

Java 10 came with ‘var’ albeit with the limitation of not using in lambdas. The error message can be shown as,

// compile error in Java 10

Function<String, String> append = (var string) -> string + " ";

However, Java 11 features help you achieve it. Allowing ‘var’ provides two prominent advantages. First of all, it introduces uniformity in the mental model for ‘var’ through the removal of a special case. The second advantage is the facility for type annotations on lambda parameters without the need for a full type name. The example for the second advantage is shown as follows.

List<EnterpriseGradeType<With, Generics>> types = /*...*/;

types.stream()

    // this is fine, but we need @Nonnull on the type

    .filter(type -> check(type))

    // in Java 10, we need to do this ~> ugh!

    .filter((@Nonnull EnterpriseGradeType<With, Generics> type) -> check(type))

    // in Java 11, we can do this ~> better

    .filter((@Nonnull var type) -> check(type))

Java 11 supports mixing implicit types, explicit types and ‘var’ in lambdas albeit with complex implementation. However, you may have to add ‘var’ to all parameters for applying annotations.

2. String::lines

Another new feature in Java 11 is the ‘String::lines’ which helps in streaming lines. The Java 11 features of String::lines are ideal for situations where you have a multiline string. Take the following example.

var multiline = "This\r\nis a\r\nmultiline\r\nstring";

multiline.lines()

    // we now have a `Stream<String>`

    .map(line -> "// " + line)

    .forEach(System.out::println);

// OUTPUT:

// This

// is a

// multiline

// string

You can note that the string uses Windows’ \r\n and the “lines ()” splits it. The method assumes \r, \n, and \r\n as line terminators even if they are mixed in the same string. Streamed lines do not contain a line terminator, and they could be empty such as “like\n\nin this\n\ncase” having five lines. However, the line at the end of the string is ignored if it is empty such as “like\nhere\n” with two lines. With the “String::lines” feature, search for new line terminators is faster, and performance improves considerably.

3. New Characters, Scripts, and Blocks

The notable difference between different versions of Java and Java 11 is the introduction of 16,018 new characters. Java 11 has added 128 emoji characters, 19 symbols ideal for the new 4K TV standard, and Bitcoin signs. Also, you can find ten new scripts and 18 new blocks. The ten new scripts in Java 11 include Adlam, Marchen, Tangut, Bhaiksuki, Newa, Soyombo, Masaram Gondi, Zanabazar Square, Osage and Nushu.

Among the 18 new blocks, ten are specifically ideal for the ten new scripts. The remaining eight new blocks are ideal for existing scripts. The existing scripts include Cyrillic Extended-C, Mongolian Supplement, Tangut Components, Kana Extended-A, Ideographic Symbols and Punctuation, Syriac Supplement, CJK Extension F and Glagolitic Supplement.

4. Standard HTTP Client

Another prominent difference between different versions of Java and Java 11 is the standardization of incubated HTTP client API. The HTTP Client API found an introduction in JDK 9 and has been updated in JDK 10 to JEP321 HTTP. Now, there is no incubating API in the “jdk.incubator.http” package as before. Code using types from the “jdk.incubator.http” package needs updates for importing HTTP types from “java.net.http” standard package.

5. .toArray(IntFunction) Default Method

After the Java 11 release date, another new feature in Java 11 also comes to the front. The new feature is the .toArray(IntFunction) default method, which is now a part of the ‘java.util.Collection’ interface. The method helps in transferring elements in the collection to a newly created array having specific runtime type. You can assume it as an overload of the toArray (T[ ]) method used for taking array instance as an argument.

6. Epsilon Garbage Collector

The addition of JEP 318 Epsilon to the top Java 11 features is also another notable highlight. The No-Op garbage collector is ideal for handling only memory allocation without implementing any memory reclamation apparatus. Epsilon GC is also helpful for cost-benefit comparison of other garbage collectors and performance testing.

7. Low-overhead Heap Profiling

Java 11 provides the feature of a low-overhead approach to sampling of Java heap allocations through the JVMTI. The design of this approach is ideal for addressing certain goals. First of all, low-overhead is at a sufficient level for default activation. The next benefit is to obtain information about live and dead Java objects. The JVMTI is a well-defined and programmatic interface that provides ease of access. You would also find low-overhead heap profiling as one of the likely additions to Java 12 features.

Also Read: How to achieve Oracle Certified Java SE 11 Developer certification?

8. Improved KeyStore Mechanisms

Security precedents for Java 12 features can take inspiration from Java 11. The new and improved KeyStore mechanisms in Java 11 can surely provide valid proof for that. You can find a new security property with the name ‘jceks.key.serialFilter’ in Java 11. JCEKS KeyStore users this security filter at the time of deserialization of encrypted key object housed in a SecretKeyEntry. Without any configuration, the filter result renders an UNDECIDED value and obtains default configuration by ‘jdk.serialFilter.’

9. Z Garbage Collector

One of the crucial new entries in top Java 11 features is the ZGC or Z garbage collector. It is a scalable low-latency garbage collected ideal for addressing specific objectives. The Z garbage collector ensures that pause times do not go beyond 10ms. It also ensures that pause times do not increase with the size of the heap or live-set. Finally, ZGC also manages heaps of varying sizes from 100 megabytes to multi terabytes.

10. Dynamic Allocation of Compiler Threads

Dynamic control of compiler threads is possible now in Java 11 with a new command line flag. The command-line flag is ‘-XX: +UseDynamicNumberOfCompilerThreads.’ The VM starts numerous compiler threads on systems with multiple CPUs in the tiered compilation mode. There is no concern for the number of compilation requests or available memory with this command line flag. However, this can lead to inefficient use of resources as idle threads could also consume memory. So, with the new command line flag, implementation has changed. Now, only one compiler thread of each type initiates at startup, and then the starting and shutdown of subsequent threats are subject to dynamic management.

10. New File Methods

New file methods among Java 11 features are also prominent attractions in the new Java release. The new file methods include ‘writeString()’, ‘readString()’ and ‘isSameFile()’. ‘writeString()’ is ideal for writing some content in a file while ‘readString()’ is ideal for reading contents in a file. The ‘isSameFile()’ method helps in knowing whether two paths identify the same file.

Final Words

An observation of the various new Java 11 features clearly shows the path for more improvements in future Java releases. Java 11 also has many new improvements in a place like other new releases. The most interesting highlight about Java 11 is that it is a stable Long-Term Support (LTS) release of Java. After Java 8, this is the second LTS release of Java. However, you may not discover any changes regarding the casting in Java

This implies the foundation for Java 12 being another Long-Term Support release. As we took a tour of the new features in Java 11, we found that many old features are missing. For example, SNMP Agent and Java Deployment Technologies are not available in Java 11. Java 11 has surely brought some drastic changes to the Java landscape. So, if you want to try out new features in Java 11, then purchase your license and get started! 

If you are well-versed with the Java SE 11 platform, it’s time to get recognition as Oracle Certified Java SE 11 Developer certification. You need to pass Java SE 11 Developer 1Z0-819 exam to become an Oracle certified Java SE 11 Developer, check the Oracle Certifications List, and start your preparation now!

About Aditi Malhotra

Aditi Malhotra is the Content Marketing Manager at Whizlabs. Having a Master in Journalism and Mass Communication, she helps businesses stop playing around with Content Marketing and start seeing tangible ROI. A writer by day and a reader by night, she is a fine blend of both reality and fantasy. Apart from her professional commitments, she is also endearing to publish a book authored by her very soon.

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top