-
Notifications
You must be signed in to change notification settings - Fork 0
Java 11
Release Date: September 25, 2018 | Type: LTS | Status: ✅ Active (widely deployed in production)
Java 11 is the first LTS after Java 8 and, for many companies, the version they finally migrated to from Java 8. It ships a standard HTTP Client, useful String/Files methods, and removes several Java EE modules that used to ship with the JDK by default.
flowchart TD
J8["Java 8 LTS\n2014"] -->|"4 years, most\nenterprise apps stayed here"| J11["Java 11 LTS\n2018"]
J11 --> A["New HTTP Client"]
J11 --> B["String/Files QoL methods"]
J11 --> C["var in lambdas"]
J11 --> D["Java EE modules removed"]
What: A modern, fluent HTTP/2-capable client — finally replacing HttpURLConnection for real-world use.
HttpClient client = HttpClient.newBuilder()
.version(HttpClient.Version.HTTP_2)
.connectTimeout(Duration.ofSeconds(10))
.build();
// Synchronous
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.example.com/users"))
.header("Accept", "application/json")
.GET()
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
// Asynchronous
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println)
.join();sequenceDiagram
participant App
participant HttpClient
participant Server
App->>HttpClient: sendAsync(request)
HttpClient->>Server: HTTP/2 request
Server-->>HttpClient: response
HttpClient-->>App: CompletableFuture<HttpResponse>
App->>App: thenApply / thenAccept
" hello ".isBlank(); // false
" ".isBlank(); // true
"line1\nline2\nline3".lines() // Stream<String>
.forEach(System.out::println);
"ab".repeat(3); // "ababab"
" padded ".strip(); // "padded" (Unicode-aware, unlike trim())
" padded ".stripLeading(); // "padded "
" padded ".stripTrailing(); // " padded"strip() vs trim(): trim() only removes characters <= U+0020. strip() uses Character.isWhitespace(), correctly handling Unicode whitespace.
// Before: multiple lines with streams/readers
String content = new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
// Java 11
String content = Files.readString(Path.of("data.txt"));
Files.writeString(Path.of("output.txt"), "Hello, Java 11!");// Allows applying annotations to lambda parameters, which was previously impossible
list.stream()
.map((@NonNull var x) -> x.trim())
.collect(Collectors.toList());
// Mostly used for consistency, since annotations are the real motivator
BiFunction<Integer, Integer, Integer> add = (var a, var b) -> a + b;# No need to compile first!
java HelloWorld.java
# Even works with shebang scripts on Unix
#!/usr/bin/java --source 11
public class Script {
public static void main(String[] args) {
System.out.println("Run directly!");
}
}# Built into the JDK, low-overhead production profiling
java -XX:StartFlightRecording=duration=60s,filename=recording.jfr -jar app.jar✅ Migrate from HttpURLConnection/Apache HttpClient to java.net.http.HttpClient for new code
✅ Use Files.readString()/writeString() for small text files instead of stream boilerplate
✅ Use .strip() instead of .trim() going forward — better Unicode correctness
❌ Don't assume Java EE libraries (JAXB, JAX-WS, etc.) are still on the classpath — add them explicitly as dependencies
| Removed / Changed | What to do |
|---|---|
java.xml.bind (JAXB) |
Add jakarta.xml.bind:jakarta.xml.bind-api + an impl (e.g., org.glassfish.jaxb) |
java.xml.ws (JAX-WS) |
Add com.sun.xml.ws:rt or migrate off SOAP |
java.corba |
Rare in modern apps; migrate off CORBA |
java.se.ee aggregator module |
No longer implicitly available |
-XX:+UseConcMarkSweepGC deprecated |
Move to G1 (default) or ZGC |
| Nashorn JS engine | Deprecated (removed in 15) — use GraalVM if you need embedded JS |
flowchart LR
A[Java 8 App] -->|Add explicit deps for\nremoved EE modules| B[Compiles on 11]
B -->|Run full test suite| C[Validate on 11]
C -->|Update CI/CD JDK| D[Deployed on 11]