Java 11
Developer Features:
New String Methods
New File Methods
Collection to an Array
Not Predicate Method
Local variable syntax for lambda
HTTP client
Nest Based Access Control
Running java File
Performance Enhancements:
Dynamic class file constants
Improved Aarch64 Intrinsics
No Op Garbage Collector
Flight Recorder
Remove deprecated modules
1.New String Methods :
isBlank() : boolean
lines(): Stream
strip()→ Removes white/blank spaces from both ends
stripLeading()→ Remove from the front end
stripTrailing()→Remove white/blank spced from the back side
repeat()→ it will repeact the string by the input parameter number
2.New File Methods:
We can use the new readString and writeString static methods from the Files class
Path filePath = Files.writeString(Files.createTempFile(tempDir, "demo", ".txt"), "Sample text");
String fileContent = Files.readString(filePath);
assertThat(fileContent).isEqualTo("Sample text");
3.Collection to an Array:
Java 11 Optimization: With Java 11, toArray
can dynamically optimize by allocating exactly the required array size if a zero-length array is passed (new String[0]
), resulting in less memory waste and improved performance in some scenarios.
List names = List.of("Alice", "Bob", "Charlie");
Uses optimized array allocation for toArray(new String[0])
in Java 11 String[] namesArray = names.toArray(new String[0]);
4.Not Predicate Method:
Predicate not(Predicate<? super T> target);
Predicate.not() is a static utility method that are added in the predicate interface which gives more readability.
5.Local variable syntax for lambda:
we can use var keyword
6.HTTP client:
(In Java, an incubator module is a way to introduce and test new features in the Java platform without fully committing them to the standard API. Incubator modules allow developers to experiment with new functionality, get community feedback, and make improvements before finalizing them in a future Java release).
In Java 9, the HTTP client was part of the incubator modules and not ready for production. Java 11 finalized this feature, making it a stable part of the Java standard library under the package java.net
.http
.
7.Flight Recorder:
Java Flight Recorder (JFR) is a valuable tool for monitoring and profiling Java applications, introduced in Java 11.
It is used for when app crash it gives the detailed information about the app crash it like log
For Example:
Imagine a scenario where your Java application suddenly crashes or experiences a performance drop. By using Java Flight Recorder, you can:
Capture the data leading up to the crash or slowdown.
Analyze the collected events to identify memory leaks, thread contention, excessive garbage collection, or other performance bottlenecks.
Generate reports to share with your development team for further investigation.