10 Must-Know Features of Java 11 for 2023 – IQCode

Top Java 11 Features You Should Know

Java 11 comes with several new features and enhancements. Here are the top ones:

1. New HTTP (and WebSocket) Client

Java 11 introduces a new HTTP client API that can be used to make asynchronous and synchronous HTTP requests. This new client also supports WebSockets.

2. Nested Classes Attributes’ Visibility Management

In Java 11, nested classes have been given access to private members of their enclosing classes.

3. Epsilon: A No-Op Garbage Collector

Epsilon is a new experimental garbage collector included with Java 11 that does nothing when a garbage collection is needed. This is useful for performance testing and debugging.

4. New Characters, Scripts, and Blocks

Java 11 introduces several new characters, scripts, and blocks, including the Japanese and Korean era names and the Unicode 11.0 standard.

5. Java Flight Recorder

Java Flight Recorder is now available in OpenJDK 11. This tool allows developers to collect data about the JVM and the application running on it.

6. Improvements to APIs

Java 11 includes several improvements to existing APIs, including the addition of new methods to the String class and enhancements to the Optional class.

7. Deprecations and Deletions

Java 11 has deprecated and removed several features, including the Java EE and CORBA modules.

8. Other Enhancements

Other enhancements in Java 11 include updates to the Javadoc tool, better performance for the G1 garbage collector, and improved support for Docker containers.

9. Long-Term Support (LTS)

Java 11 is an LTS release, which means that it will receive long-term support from Oracle.

Conclusion

Java 11 is a significant update with several new features and improvements. It is recommended that developers upgrade to take advantage of these enhancements.

FAQs

Q.1: What is special about Java 11?
A: Java 11 introduces several new features and enhancements, including a new HTTP client API, improvements to APIs, and Java Flight Recorder.

Q.2: What are the advantages of Java 11?
A: The advantages of Java 11 include new features, improved performance, and LTS support.

Q.3: What is the difference between Java 8 and Java 11?
A: Java 11 includes new features and improvements not available in Java 8, such as a new HTTP client API and enhancements to APIs.

Q.4: Does Spring Boot support Java 11?
A: Yes, Spring Boot 2.1 and later versions fully support Java 11.

Additional Resources

For more information about Java 11, check out the official release notes from Oracle:

https://www.oracle.com/java/technologies/javase/11-relnote-issues.html

Exploring the Latest Java 11 Features

Java has been evolving since its launch in 1995. With the six-month release cycle, staying up to date requires effort. Oracle recently made Java Development Kit (JDK) 11 available, which is the most efficient version in Java’s history and the first Long Term Support (LTS) update.

Java 11 is the second LTS release after Java 8, making it highly useful for tech enthusiasts. However, note that the Oracle JDK is no longer free for commercial purposes. The new releases do not affect Java programming certification’s effectiveness.

Let’s take a closer look at Java 11 features: Code snippets.


// 1. Local-Variable Syntax for Lambda Parameters
(map) -> map.forEach((key, value) -> System.out.println(key + ":" + value));

// 2. HTTP Client (Standard)
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://www.example.com/"))
.build();
HttpResponse response =
client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

// 3. Improved Security
AlgorithmConstraints ac = AlgorithmConstraints.PROHIBIT_TLSv1_3;
SSLParameters params = new SSLParameters();
params.setAlgorithmConstraints(ac);
params.setEndpointIdentificationAlgorithm("HTTPS");
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(Verifier);

These and many other features make Java 11 a significant update for developers to improve their coding experience.

Must-Know Java 11 Features

Java 11 introduces several new features and enhancements for developers to improve their coding experience. Here’s a brief look at the top features:


1. String methods for improved performance and security
2. HTTP Client API
3. Local variable syntax for lambda parameters
4. Launch single-file source-code programs
5. Improved deprecated APIs

Stay up-to-date with these features to make the most of Java 11. Happy coding!

New HTTP and WebSocket Client in Java 11

Java 11 introduces a new HTTP client. Previously available as an incubator module since Java 9, it has now become a part of the standard API in the java.net.http module. It includes the following interfaces and classes:

– HttpClient is the main interface.
– HttpRequest is the request data.
– HttpResponse is the response data.
– WebSocket is the WebSocket client entry point.

This new client significantly improves Java’s existing HTTP client support in java.net.HttpURLConnection, due to its various advantages such as:

– EASY API AND BETTER READABILITY: A fluent API ensures constructing requests and processing responses make coding more straightforward, simpler to understand, and less verbose. The builder pattern increases the client’s thread safety and requests/responses.
– COMPATIBLE WITH OTHER JAVA APIs: Uses contemporary Java language features and APIs like Lambda expressions, Optional, and the standard java.time.Date and Time API, among others.
– SUPPORTS NON-BLOCKING I/O: Supports executing requests asynchronously without causing a thread blockage, using CompletableFutures.
– PROTOCOL SUPPORT: Along with HTTP/1.1, the new client includes support for HTTP/2 (default with automatic negotiation and fallback to HTTP/1.1) and WebSocket.

Nested Class Attributes Visibility Management

In Java, multiple classes can be declared in a single source file, including nested classes. However, users assume that nested classes have the same access regime relative to their attributes as their host classes. To maintain this assumption, compilers should expand private attribute access to classes in the same package by incorporating access bridges. These bridges undermine encapsulation and can be misleading.

To address this, JDK 11 has added two new attributes to classes, NestMembers and NestHost, and three new methods to java.lang.Class: getNestHost(), getNestMembers(), and isNestmateof(Class). These changes allow for a formal group or “nest” of nested classes that share a common access control technique, resulting in simpler, safer, and more transparent code.

Epsilon GC: Low Latency, No-Op Garbage Collector

JDK 11 has introduced a new garbage collector, Epsilon GC. Unlike other GCs, it does not work on memory reclamation and simply shuts down the JVM when the heap runs out, resulting in potential memory loss.

The advantage of using Epsilon GC is that it provides the lowest possible latency overhead and has a bounded memory allocation limit. It is beneficial for performance testing and last-drop latency enhancements in applications that require ultra-low latency.

Epsilon GC can be executed by passing the “-Xmx4g” argument and observed with “-XX:HeapDumpOnOutOfMemoryError” for learning about memory allocation and application performance. In scenarios where long GC cycles can delay recovery, Epsilon GC can be a better recovery strategy.

New Characters, Scripts, and Blocks in Java 11

Java 11 introduces 16,018 new characters, including 19 symbols, 128 emoticons, suitable for 4K TVs, and Bitcoin signs. It also includes 18 new blocks and 10 new scripts, such as Newa, Soyombo, Adlam, Osage, and more. Out of the 18 new blocks, ten are perfect for the new scripts, while the remaining eight are ideal for the existing scripts, which include Cyrillic Extended-C, Mongolian Supplement, and more.

JAVA FLIGHT RECORDER

During the development process, some issues only appear during the application’s runtime, making it difficult or even impossible to analyze and reproduce them. Java Flight Recorder (JFR) allows us to record JVM data at runtime and save it in a file for later evaluation. JFR has been a commercial feature in Oracle’s JDK for many years, but with the enhancement proposed in JDK 328, it is now available in OpenJDK for free use.

To start a Flight Recorder, you have two options: you can activate it at the beginning of the application with the following option on the java command line:

-XX:STARTFLIGHTRECORDING=FILENAME=

Alternatively, you can activate it in a running Java application using jcmd:

jcmd JFR.START FILENAME=

You can also add additional options such as “duration” to specify how long the recorder should operate.

API Improvements in JDK11

JDK 11 comes with new classes and methods which are built into existing modules, some of the most important enhancements are:

Java.lang.String:

– boolean isBlank(): Returns true if the String is blank or composed of only whitespaces. Otherwise, false.
– Stream lines(): Returns a stream of lines from the String.
– String strip(): Returns a String without leading or trailing whitespaces. This function is the ‘Unicode-aware’ version of trim().
– String repeat(int): Concatenates the original String with itself n times.
– String stripLeading(): Returns a String without its leading whitespaces.
– String stripTrailing(): Returns a String without its trailing whitespaces.
– Java.util.function: Represents a function that takes one argument and produces a result.

Java.util.function.Predicate:

– Predicate not(Predicate): Returns a negated version of Predicate passed as an argument.

Java.lang.CharSequence:

– int compare(CharSequence, CharSequence): Compares two occurrences of CharSequence in lexicographic order.

Java.lang.StringBuilder / Java.lang.StringBuffer:

– Both classes now have access to a new compareTo() method that compares the String with a StringBuffer/StringBuilder argument and returns an int in lexicographic order.

Note: This is not a comprehensive list of all the changes.

Deprecated Features in JDK

The JDK Enhancement Proposal 320 has removed several modules from the JDK, including java.xml.ws (JAX-WS), java.xml.bind (JAXB), and java.corba (CORBA), which were originally designed for the Java EE platform. These features were marked “deprecated” in Java 9 and finally removed in Java 11. The Nashorn JavaScript engine was also marked as “deprecated for removal” and will be eliminated in a future release. Additionally, the Pack200 tools and API were tagged as “deprecated” and should be erased in the upcoming Java releases. JavaFX and the related javapackager tool are now available for separate installation from the JavaFX homepage.

Java 11 Enhancements

Java 11 offers some significant enhancements to the language. Here are some of the key features:

Unicode 11 Support
—————————————————–
Java 11 now supports Unicode 11 and offers support for Java classes such as String, Character, NumericShaper, Bidi, Normalizer, and BreakIterator.

Enhanced KeyStore Mechanisms
—————————————————–
Java 11 has added a new security property, ‘jceks.key.serialFilter’, that enables users of KeyStore to use a security filter during the deserialization of encrypted key objects placed in a SecretKeyEntry.

Low-overhead Heap Profiling
—————————————————–
Java 11 offers a low-overhead method of sampling Java heap allocations via the JVMTI. This method is useful for focusing on specific goals such as obtaining data about dead and live Java objects.

Enhanced AARCH64 Intrinsics
—————————————————–
Java 11 optimizes and enhances the string and array intrinsic on AArch64 processors, as well as incorporating new intrinsics for cos, log, and sin methods of java.lang.

Launching Single-file Java Programs
—————————————————–
Java 11 supports the execution of a single-file Java program with a single command, making it ideal for beginners and fast prototyping.

To use this feature, write a single-file program with one or more classes and run it using the command ‘java MyProgram.java.’ Note that external dependencies cannot be used.

Java 11 Long-Term Support (LTS)

Java 11 can be used at different development stages, but commercial use of its latest features may require a license. After Java 11’s release, Oracle stopped providing support for Java 8, unless you pay for it. However, paid support does not include patches or security updates. Use Open JDK builds from providers, which offer flexible and upgradable options. Java 11 is an LTS release, meaning that Oracle will provide security patches for years to come. Java 9 and 10 are not LTS releases, so their support was discontinued with every new release. Java 11 brings modifications to the language, improvements to the JDK class library, tools, and experimental features. Oracle JDK requires a paid support contract, while OpenJDK 11 is free for everyone to use.

Key Takeaways from Java 11 Features Study

Java 11 offers a promising future for upcoming Java releases by incorporating recent developments. The remarkable aspect of Java 11 is being a stable Long-Term Support (LTS) release, the second one after Java 8. However, Java 11 lacks some old features such as Java Deployment Technologies and SNMP Agent. Despite this, it has brought several significant modifications to the Java landscape. To experience the latest features in Java 11, buy your license and get started!

What’s New in Java 11?

Java 11 includes significant updates, such as the replacement of the insecure RC4 cipher with new ChaCha20 and ChaCha20-Poly1305 implementations. Additionally, the cryptographic key agreement has been upgraded to use Curve25519 and Curve448, replacing the previous ECDH scheme. Java 11 also facilitates the creation of multi-release jar files, allowing library programmers to support multiple Java versions without requiring different jar files.

Advantages of Java 11

Java 11 includes several new features such as:

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

Differences Between Java 8 and Java 11



Java 8:
- Appletviewer tool available
- Less number of String methods

Java 11:
- Apppletviewer tool not available
- More String methods: repeat(n), lines(), stripLeading(), stripTrailing(), and strip()

Java 11 introduced new string methods and removed the appletviewer tool. Java 8 has fewer string methods, but includes the appletviewer tool.

Is Java 11 supported by Spring Boot?

Yes, Spring Boot 2.4 is compatible with Java 11 as well as Java 8. It also supports Java 15.

// No code required for this answer.

Resources for Learning and Practicing Java

Improve your Java skills with these resources:

Top 10 Productivity Tools for Programmers

IQCode’s Guide to the Six Categories of Information Systems (2023)

A Comprehensive Overview of Kubernetes Architecture – Explained in Detail by IQCode

Which is Better: AWS or Azure? – A Comparison by IQCode