String class: new methods isBlank, lines, strip, stripLeading, stripTrailing, and repeat.
New Method in File class We can use the new readString and writeString static methods from the Files class
Not Predicate Method
List withoutBlanks = sampleList.stream() .filter(Predicate.not(String::isBlank)) .collect(Collectors.toList());**New HTTP Client
The new HTTP API improves overall performance and provides support for both HTTP/1.1 and HTTP/2:
HttpClient httpClient = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.connectTimeout(Duration.ofSeconds(20))
.build();we don’t need to compile the Java source files with javac explicitly anymore_:_
$ javac HelloWorld.java
$ java HelloWorld
Hello Java 8!Performance Enhancements
_Dynamic Class-File Constants
Java class-file format is extended to support a new constant-pool form named CONSTANT_Dynamic. CONSTANT_Dynamic is used to support dynamic constants that are computed when a class is first loaded, rather than being hard-coded at compile time. This allows for more efficient, lazy initialization of constants. Instead of embedding a fixed value in the class file, CONSTANT_Dynamic stores a bootstrap method reference along with arguments. When the JVM encounters this constant during class loading, it calls the specified bootstrap method, which computes and returns the actual constant value. This result is then cached for future use
_Improved Aarch64 Intrinsics
Java 11 optimizes the existing string and array intrinsics on ARM64 or AArch64 processors. Additionally, new intrinsics are implemented for sin, cos, and log methods of java.lang.Math.
We use an intrinsic function like any other; however, the intrinsic function gets handled in a special way by the compiler. It leverages CPU architecture-specific assembly code to boost performance.
A No-Op Garbage Collector A new garbage collector called Epsilon is available for use in Java 11 as an experimental feature.
It’s called a No-Op (no operations) because it allocates memory but does not actually collect any garbage. Thus, Epsilon is applicable for simulating out of memory errors.
Obviously Epsilon won’t be suitable for a typical production Java application; however, there are a few specific use-cases where it could be useful:
- Performance testing
- Memory pressure testing
- VM interface testing and
- Extremely short-lived jobs In order to enable it, use the -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC flag.
*Java Flight Recorder (JFR)_
is now open-source in Open JDK**, whereas it used to be a commercial product in Oracle JDK. JFR is a profiling tool that we can use to gather diagnostics and profiling data from a running Java application