Notable features of Java 11 to 17

Amar Balu
The Fresh Writes
Published in
6 min readJun 20, 2023

--

Here are some notable features introduced in Java versions 11 to 17, along with example code:

Photo by Clément Hélardot on Unsplash

Java 11:

  1. Local-Variable Syntax for Lambda Parameters:
  • In Java 11, the ‘var’ keyword was introduced to allow the use of type inference for lambda parameters.
  • The example demonstrates how you can use the ‘var’ keyword to declare lambda parameters without explicitly specifying the type.
// Before Java 11
Function<Integer, String> oldLambda = (Integer x) -> "The number is: " + x;

// With Java 11
Function<Integer, String> newLambda = (var x) -> "The number is: " + x;

2. HTTP Client (Standard):

  • Java 11 introduced a new built-in HTTP client API that provides a more modern and flexible way to interact with HTTP services.
  • The example demonstrates how to create an HTTP client, send a GET request to a specified URI, and retrieve the response body.
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.example.com/users"))
.build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());

Java 12:

--

--

Amar Balu
The Fresh Writes

I'm a front-end developer. I love React and Redux, Java, and Data Science. I write code for fun!. Join our publication : https://medium.com/thefreshwrites