Java 11 new features
Java 11, released in September 2018, introduced several new features and improvements to the Java programming language. Here are some of the notable new features in Java 11:
- Local Variable Type Inference: Java 11 introduced local variable type inference, which allows you to declare local variables without explicitly specifying their types. This feature is similar to the "var" keyword in Kotlin.
Example:
var name = "John";
- HTTP Client: Java 11 introduced a new HTTP client API, which provides a more modern and efficient way of making HTTP requests. The API is designed to be more flexible and easier to use than the previous HTTP client API.
Example:
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://example.com"))
.build();
client.send(request, HttpResponse.BodyHandlers.ofString());
-
Improved Garbage Collection: Java 11 introduced several improvements to the garbage collector, including a new garbage collector algorithm called "ZGC" (Z Garbage Collector). ZGC is designed to provide better performance and lower pause times for large-scale applications.
-
Improved Support for Modules: Java 11 introduced several improvements to the module system, including support for module versioning and improved module resolution.
Example:
module my.module {
exports my.package;
requires java.sql;
}
- Improved Support for JSON Processing: Java 11 introduced several improvements to the JSON processing API, including support for JSON schema validation and improved performance.
Example:
JsonProcessor processor = JsonProcessor.newJsonProcessor();
JsonNode node = processor.parseJson("{"name": "John"}");
- Improved Support for XML Processing: Java 11 introduced several improvements to the XML processing API, including support for XML schema validation and improved performance.
Example:
XmlProcessor processor = XmlProcessor.newXmlProcessor();
Document doc = processor.parseXml("<root><name>John</name></root>");
-
Improved Support for Unicode: Java 11 introduced several improvements to the Unicode support, including support for Unicode 11 and improved handling of Unicode characters.
-
Improved Support for JavaFX: Java 11 introduced several improvements to the JavaFX API, including support for JavaFX 11 and improved performance.
Example:
Stage stage = new Stage();
stage.setScene(new Scene(new Label("Hello, World!")));
stage.show();
- Improved Support for Java Mission Control: Java 11 introduced several improvements to the Java Mission Control API, including support for Java Mission Control 7 and improved performance.
Example:
MissionControl mc = MissionControl.newMissionControl();
mc.start();
- Improved Support for Java Flight Recorder: Java 11 introduced several improvements to the Java Flight Recorder API, including support for Java Flight Recorder 7 and improved performance.
Example:
FlightRecorder fr = FlightRecorder.newFlightRecorder();
fr.start();
These are just a few of the many new features and improvements introduced in Java 11. For a complete list of new features and changes, you can refer to the official Java 11 documentation.