This post aims to resume java 11 news. Note that java 11 is a LTS version.
The oracle release note is available here
API updates
Strings
- String.isBlank()
- String.lines()
- String repeat(int)
- String.strip()
- String.stripLeading()
- String.stripTrailing()
- java.lang.CharSequence.compare()
- java.lang.StringBuffer.comapreTo()
- java.lang.StringBuilder.compareTo()
Predicate
- Predicate.not()
Nested classes
- Class.getNestHost()
- Class.getNestMembers()
- Class.isNestmateof(Class)
DYNAMIC CLASS-FILE CONSTANTS
The value of the constant is debined in the execution, and not in the compialtion.
The value is defined only one time.
Epsilon garbage collector
Epsilon GC handles memory allocation but does not implement any actual memory reclamation mechanism. Once the available Java heap is exhausted, the JVM will shut down.
Unicode 10
Support the latest version of Unicode, mainly in the following classes:
- Character and String in the java.lang package,
- NumericShaper in the java.awt.font package, and
- Bidi, BreakIterator, and Normalizer in the java.text package.
Launch Unique file
Before Java 11
javac -d <memory> HelloWorld.java
java -cp <memory>
After Java 11
java HelloWorld.java
Http client
This HTTP Client API, in the java.net.http
package was introduced in Java 9, updated in Java 10, now a standard feature in Java 11.
A Java 11 HttpClient
to send a simple GET request.
HttpClient httpClient = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_1_1)
.connectTimeout(Duration.ofSeconds(10))
.build();
HttpRequest request = HttpRequest.newBuilder()
.GET()
.uri(URI.create("https://httpbin.org/get"))
.setHeader("User-Agent", "Java 11 HttpClient Bot")
.build();
HttpResponse<String> response =
httpClient.send(request, HttpResponse.BodyHandlers.ofString());
HttpHeaders headers = response.headers();
headers.map().forEach((k, v) -> System.out.println(k + ":" + v));
System.out.println(response.statusCode());
System.out.println(response.body());
Removal
Java 9 deprecated the following Java EE and CORBA modules and now removed in Java 11. If you want to migrate to Java 11, make sure your project didn’t use any of the following packages or tools.
Removed packages:
- 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 six modules above)
Removed Tools:
- wsgen and wsimport (from jdk.xml.ws)
- schemagen and xjc (from jdk.xml.bind)
- idlj, orbd, servertool, and tnamesrv (from java.corba)