Top Java 11 Features You Must Know [2022]

Java 11 Features

One of the world’s most commonly utilised and in-demand programming languages, Java, since its arrival in 1995, has kept evolving. In recent years, with its periodic release cycle, it needs a bit more effort to stay at par with the new releases. Java introduces a new version of release, at an interval of every six months. Oracle made JDK (Java Development Kit) 11on September 25, 2018, available. The latest update of the reference implementation of the Java SE platform, JDK 11, is the most efficient version 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 tech enthusiasts were waiting eagerly for the new release and working with the latest features of Java 11. After Java 8, Java 11 appears to be the second LTS release, speaking enough for its usefulness. With the advent of Java 11, Oracle JDK is not available anymore for a commercial purpose with zero costs. Additionally, you should note that the new releases do not influence the effectiveness of a Java programming certification. Now, let us look into the Java 11 features for better understanding what Java 11 brings to the table!

Java 11

Top Java 11 Features

Top Java 11 Features

1. New HTTP (and WebSocket) Client

Java 11 comprises a new HTTP client. (Since Java 9, this had been available as an ‘incubator’ module, but it has now graduated following the finalisation of its API). It contained the client in the java.net.http module/package and comprises the following important interfaces and classes:

  • HttpClient is the entry point for utilising the API.
  • HttpRequest is a request to be sent through the HttpClient.
  • HttpResponse is the result of an HttpRequest call.
  • WebSocket is the entry point for building up a WebSocket client.

The client is a considerable enhancement over Java’s continuing HTTP client support –  java.net.HttpURLConnection – which, owing to the various limitations, wasn’t a feasible choice for production usage. The enhancements include.

Confused about your next job?

In 3 simple steps you can find your personalised career roadmap in Software development for FREE



Expand in New Tab 

Easier API and Better Code Readability – A fluent API ensures constructing requests and processing responses are easier to code, simpler to understand, and less verbose. Usage of the Builder pattern rather than setter techniques also enhances client’s thread-safety and its requests/responses.

Compatible with other contemporary Java APIs – The client backs using contemporary Java (8+) language features and APIs, such as Lambda expressions, Optional, and the standard (java.time) Date and Time API, and so on.

Support for Non-blocking I/O – The client supports executing requests without blocking the current thread through the usage of an async API/callbacks, which utilise java.util.concurrent.CompletableFuture

Protocol support – Besides HTTP/1.1, the latest HTTP client also offers support for HTTP/2 (the default, with automatic negotiation and fallback to HTTP/1.1) along with WebSocket.

2. Nested classes attributes’ visibility management

Java supports several classes to be declared in a single source file, like nested classes. However, from the user’s perspective, they are regarded to belong to the “same class”. Thus, users assume them to have a shared access regime relative to their attributes. To sustain these assumptions, compilers should expand private attribute access to classes in the same package by incorporating access bridges. They assembled an invocation of a private member into a call of a compiler-generated method (getter) in the target class, which accesses the proposed private member.

For instance, with a NestedClass class, nested within a NestingClass class, which requires accessing one of the private attributes of the host class:

The compiler splits the two classes and sets up a public access method to nestingInt adopted by the NestedClass class:

These bridges undermine the encapsulation (private no longer has the same meaning) and can mislead users and tools. A formal idea of a group of nesting class files (or nest), where nest partners share a common access control technique, makes it plausible to get the anticipated outcome directly in a simpler, more safe, and more transparent way. To readily connect nested classes and hosts in JDK 11, it has incorporated two new attributes to the classes: NestMembers (nest members) and NestHost (new host)

Also, they have added 3 methods to java.lang.Class

  • Class getNestHost ()
  • Class [] getNestMembers ()
  • boolean isNestmateof (Class)

3. Epsilon: A No-Op Garbage Collector 

We got a new garbage collector, Epsilon GC with JDK 11. This GC manages memory allocation but doesn’t work on the mechanism of actual memory reclamation. Thus, when the overall java heap runs out, throwing an OutOfMemoryError, it will shutdown the JVM.

The idea of building this GC is to offer the lowest possible latency overhead with a bounded memory allocation limit, but at the cost of memory throughout. Basically, it implies that learning about the heap will be sufficient for our application, so we don’t need the JVM to utilise resources to execute GC tasks(short pauses). It eliminates the impact GC has on execution and the code runs in absolute isolation.

  • It can mainly utilise epsilon GC for testing the performance, like how garbage collection influences your application’s performance and what is the threshold of your application memory. If you assume that your application will require 4GB of memory then with “-Xmx4g” argument, we can execute it and if the JVM collapses, with “-XX:HeapDumpOnOutOfMemoryError” enabled, we can rerun it. Then we can observe the heap dump to learn where or which process has spent more memory.

  • Also, Epsilon GC is beneficial for applications where we have to perform a last-drop latency enhancements, mostly for applications that are sensitive to ultra latency, where we are certain about memory allotments and know the application memory footprint and where receiving the GC cycle can be a concern. In those applications, long GC cycle can be an issue as that stretches the failure detection and conclusively recovery gets delayed. In such scenarios, allowing load balancers to figure out failure is at times a better recovery strategy than accepting a GC cycle.

4. New Characters, Scripts, and Blocks

The striking difference between various versions of Java and Java 11 is the addition of 16,018 new characters. Java 11 has incorporated 19 symbols, 128 emoji characters, perfect for the new 4K TV standard, and Bitcoin signs. Additionally, you can come across 18 new blocks and 10 new scripts and. The 10 latest scripts in Java 11 are Newa, Soyombo, Adlam, Osage, Marchen, Masaram Gondi, Tangut, Bhaiksuki, Zanabazar Square, and Nushu. Among the latest 18 blocks, ten are specially ideal for the ten new scripts. Rest of the eight new blocks are the right fit for existing scripts. The existing scripts are Tangut Components, Cyrillic Extended-C, Mongolian Supplement, Ideographic Symbols and Punctuation, Kana Extended-A, CJK Extension F, Syriac Supplement, and Glagolitic Supplement.

5. Java Flight Recorder

Many tools assist us in analysing and resolving errors during the process of development. However, specific issues only appear at the application’s runtime. Analysing them is often laborious or impossible, as we often cannot reproduce such mistakes. Java Flight Recorder (JFR) can help us by recording JVM data at runtime and ensuring it is available in a file for successive evaluation. For many years, Flight Recorder has already been there as a commercial feature in Oracle’s JDK. With JDK Enhancement Proposal 328, it becomes part of the OpenJDK and can be utilised freely.

How to Initiate a Flight Recorder?

You can initiate Flight Recorder in two manners. First, with the help of the following option on the java command line, you can activate Flight Recorder at the beginning of an application:

-XX:StartFlightRecording=filename=<file name>

Second, in a running Java application, you can utilise jcmd to activate Flight Recorder:

jcmd JFR.start filename=<file name>

You can mention many options; for instance, you can make use of “duration” to specify how long the recorder should operate.

6. APis Improvements

JDK 11 encloses several new classes and methods built into existing modules. The list mentioned below is a non-comprehensive overview, emphasising the enhancements that seem to appear to be the most important.

java.lang.String:

  • boolean isBlank (): If the String is blank or made of just whitespaces, returns true, else false.
  • stream lines (): Returns a stream of lines derived from the String.
  • String strip (): returns a String clear of leading and trailing whitespaces. In simple terms, strip () is the “Unicode-aware” version of trim () whose definition of whitespace goes back from Java’s first versions.
  • string repeat (int): returns a string that is the original String concatenated with itself n times.
  • String stripLeading (): Returns a String free of its leading whitespaces.
  • String stripTrailing (): returns a String devoid of trailing white spaces.
  • Java.util.function.: It represents a function which takes in one argument and produces a result

java.util.function.Predicate

  • Predicate not (Predicate). Returns a Predicate which is the repudiation of the Predicate passed as an argument. For instance, to filter a list:

java.lang.CharSequence

  • int compare (CharSequence, CharSequence): juxtaposes two occurrences of CharSequence in lexicographic order. Returns a positive, null or negative value.

java.lang.StrinBuilder / java.lang.StringBuffer

  • Now, both classes have access to a new compareTo () approach that receives a StringBuffer / StringBuilder argument and returns an int. The logic of comparison follows the exact lexicographic order as for the CharSequence class’s new method.

7. Deprecations and Deletions

This lists talks about all the “deprecated” features or features that are removed from the JDK.

Eliminate the Java EE and CORBA Modules

  • JDK Enhancement Proposal 320 gets rid of the below mentioned modules from the JDK:
  • java.xml.ws (JAX-WS)
  • java.xml.bind (JAXB)
  • java.activation (JAF)
  • java.xml.ws.annotation (Common Annotations)
  • java.corba (CORBA)
  • java.transaction (JTA)
  • java.se.ee (aggregator module for the 6 formerly discussed modules)
  • jdk.xml.ws (tools for JAX-WS)
  • jdk.xml.bind (tools for JAXB)

Initially, the listed technologies were designed for the Java EE platform and were incorporated into the standard edition “Java SE” when Java 6 was released. They were marked “deprecated” in Java 9 and finally got rid of with Java 11. After upgrading to Java 11, should you miss these libraries, you can bring them back to your project, example through Maven dependencies.

Discontinue the Nashorn JavaScript Engine

In JDK 8, the JavaScript engine, “Rhino” was introduced and with JEP 335 in Java 11, it was tagged as “deprecated for removal” and is to be eliminated altogether in one of the subsequent versions. The reason for this is the quick advancement of ECMAScript (the standard behind JavaScript) and the node.js engine, which has made further improvement of Rhino too pricey.

Discontinue the Pack200 Tools and API

In Java 5, it introduced a special compression method Pack200 that reaches greater compression rates than standard methods, specifically for .jar and .class files. In the early 2000s, Pack200 saved as much bandwidth as possible. Nonetheless, the algorithm is complicated, and the further enhancement costs are no longer in line with the usefulness in times of 100-Mbit Internet lines. Thus, the tool has been tagged as “deprecated” with JDK Enhancement Proposal 336 and should be erased in one of the following Java releases.

JavaFX Goes Its Own Way

With Java 11, JavaFX and the related javapackager tool are no longer shipped with the JDK. Rather, you can a separate SDK can be downloaded from the JavaFX homepage.

8. Other Enhancements 

Incorporated support for Unicode 11

Java 11 has added Unicode 11 support to prevailing platform APIs. Mentioned below are the following Java classes that are mostly supported with Unicode 10:

  • In the java.awt.font package: NumericShaper
  • In the java.lang package: String and Character
  • In the java.text package: Bidi, Normalizer and BreakIterator

This upgrade comprises Unicode 9 changes and incorporates ten new scripts and 16,018 characters.

Enhanced KeyStore Mechanisms

Java 11 can inspire the security precedents for Java 12 features. The enhanced KeyStore mechanisms in Java 11 can certainly give valid proof of that. In Java 11, you can look for a new security property with the name ‘jceks.key.serialFilter’. Users of JCEKS KeyStore can use this security filter during the time of deserialization of encrypted key object placed in a SecretKeyEntry. With no configuration, the result of the filter renders an UNDECIDED value and gets default configuration by ‘jdk.serialFilte

Low-overhead Heap Profiling

Java 11 offers the feature of a low-overhead method of sampling of Java heap allocations via the JVMTI. The idea of this method is perfect for focusing on specific goals. First, low-overhead is at a satisfactory level for default activation. The next usefulness is to get data about dead and live Java objects. The JVMTI is a well-defined and programmatic interface that offers easy access. You would also learn about low-overhead heap profiling as one of the probable enhancements to Java 12 features.

Enhanced Aarch64 Intrinsics

The compiler handles another function, an Intrinsic in some special way. They take benefit from the CPU architecture-specific assembly code to enhance the performance. Java 11 optimised and enhanced the prevailing string and array intrinsic on AArch64(or ARM64) processors. Also, Java 11 incorporated new Intrinsics for cos, log and sin methods of the java.lang.

Launching Single-File Java Program

Java 11 backs the execution of a single file Java program with a single command.

Details

Facilitates high speed prototyping and beginner friendly Java development.
It ought to be a single-file program only, having one or more classes.
We can’t utilise external dependencies./

How to use?

Let’s assume the file name is MyProgram.java, to RUN it, we only require to utilise java MyProgram.java.

9. Long-Term Support (LTS)

You can utilise Java 11 in various phases of development. Nonetheless, commercial usage of the latest Java 11 features would call for a license. After the release date of Java 11, many essential details came to the forefront. For example, Oracle would not lend support to Java 8 post January 2019. You can keep using Java 8 by paying for support, though you would not get any patches or security updates. Since you cannot utilise Oracle JDK any longer with no costs, you can download Open JDK builds. Many providers offer flexible options, and you can utilise Open JDK builds from these providers and also upgrade them when needed. With Java 11, on September 25, 2018, the first LTS release of the JDK since the shift to the six-month release cycle was published. “Long-Term Support (LTS)” implies that Oracle will give this version with security patches for many years. The last LTS release was Java 8, Java 9 and 10 were not LTS releases, which implies that support for these versions was discontinued with every successive release.

In this article, we have sorted the changes in Java 11 as per the relevance for daily programmer work. First comes the modifications to the language itself, accompanied by improvements to the JDK class library, tools, and experimental features. And lastly, deletions, deprecations, and other slight adjustments. It is also necessary to learn that from version 11 onwards, programmers can only utilise freely the Oracle JDK. Businesses call for a paid support contract with Oracle. OpenJDK 11 is for everyone and free to use

Conclusions

A study of the different new Java 11 features reveals the path for more enhancements in future Java releases. Also, Java 11 incorporated different recent developments in a place, like other new releases. The most striking feature about Java 11 is that it is a steady Long-Term Support (LTS) release of Java. Post Java 8, this is the 2nd LTS release of Java. You may not recognise any developments regarding the casting in Java. This means that Java 12 being another Long-Term Support release. As we looked into the new features in Java 11, we discovered that it misses many old features. For instance, Java Deployment Technologies and SNMP Agent are not available in Java 11. Java 11 has surely brought some radical modifications to the Java landscape. Thus, if you wish to try out the latest features in Java 11, then buy your license and get started! 

FAQs

Q: What is special about Java 11?
Answer: Java 11 incorporated a few more modifications that are necessary to highlight like New ChaCha20 and ChaCha20-Poly1305 cipher implementations change the insecure RC4 stream cipher. Support for cryptographic key agreement with Curve25519 and Curve448 replaces the prevailing ECDH scheme.

It is plausible in Java 11 to develop a jar file that comprises several Java-release-specific versions of class files. Multi-release jar files make it feasible for library programmers to back different versions of Java without having to ship different versions of jar files.

Q: What are the advantages of Java 11?
Answer: Java 11 incorporates new Java Enhancement Proposals. The advantages are as follows:

  • Nest-based access control
  • Dynamic class-file constraints
  • Enhance Aarch64 Intrinsics
  • Epsilon: A No-Op Garbage Collector
  • Eliminate the Java EE and CORBA Modules
  • HTTP Client (Standard)

Q: What is the difference between Java 8 and Java 11?
Answer: In Java 8, the appletviewer tool is available whereas in Java 11, the tool is not available. Java 8 has fewer string methods whereas in Java 11, different new methods of String like repeat(n), lines(), stripLeading(), stripTrailing(), and strip() are introduced.

Q: Does spring boot support Java 11?
Answer: Spring Boot 2.4 backs Java 15 while also remaining compatible with Java 11 and 8.

Additional Resources

Previous Post
Machine Learning Courses

9 Best Machine Learning Courses [2022] 

Next Post
AWS Projects

Top AWS Projects for Beginners to Advanced [With Source Code]

Total
0
Share