Java 11 Features

Java 11 is a Long-Term Support (LTS) release that introduced several important API enhancements, performance improvements, and new utilities for developers. It became the most widely adopted enterprise Java version after Java 8.


1. New String Methods

Java 11 introduced useful methods in the String class.


String text = "  Java  ";

System.out.println(text.strip());
System.out.println(text.isBlank());
System.out.println("Java\nPython".lines().count());
New methods include strip(), isBlank(), and lines().

2. HTTP Client API

Java 11 introduced a modern HTTP client to replace the older HttpURLConnection.


HttpClient client = HttpClient.newHttpClient();

HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("https://example.com"))
        .build();

HttpResponse response =
        client.send(request, HttpResponse.BodyHandlers.ofString());

System.out.println(response.body());
Supports HTTP/1.1, HTTP/2, synchronous and asynchronous requests.

3. Running Java Files Without Compilation

Java 11 allows running single-file programs directly.


java HelloWorld.java
Useful for scripting and quick testing.

4. Local Variable Syntax for Lambda

Allows using var in lambda parameters.


list.forEach((var item) -> {
    System.out.println(item);
});
Improves readability and allows annotations in lambda parameters.

5. Collection to Array Method

Java 11 improved the toArray() method for collections.


List list = List.of("Java", "Python");

String[] array = list.toArray(String[]::new);
This method avoids unnecessary array creation.

6. Removed Java EE Modules

Java 11 removed several outdated modules.

  • JAXB
  • JAX-WS
  • CORBA
These modules are now available as external dependencies.

Quick Revision Summary

  • New String methods (strip, isBlank, lines)
  • HTTP Client API
  • Run Java files without compilation
  • Lambda parameter var support
  • Improved Collection toArray()
  • Removed Java EE modules

0 comments

Leave a comment