Java 11

Java 11 is a long-term support (LTS) release of the Java platform, with a number of new features and enhancements. Here is a comparison of some of the key upgraded features in Java 11 with Java 8 and older versions:

Local-variable type inference (var) allows you to omit the type of a local variable, if the compiler can infer it from the context. This can make code more concise and readable.

The HTTP client in Java 11 provides a modern and efficient way to make HTTP requests.

String enhancements in Java 11 include new methods for working with strings, such as isBlank() and lines().

The garbage collector (GC) in Java 11 has been improved to reduce garbage collection pauses and improve performance.

The concurrency API in Java 11 has been enhanced with new features such as Flow and CompletableFuture.

JavaFX has been removed from Java 11. If you need to use JavaFX, you can download it as a separate module.

In addition to these key features, Java 11 also includes a number of other smaller enhancements, such as the new DateTimeFormatter class and the new String.join() method.

Overall, Java 11 is a significant upgrade over Java 8 and older versions of the Java platform, with a number of new features and enhancements that make it easier, more efficient, and more expressive to write Java code.

Here are some examples of how the new features in Java 11 can be used to improve code:

Local-variable type inference (var):

Java

```
<// Java 8:
int number = 10;

// Java 11:
var number = 10;

```

HTTP client:

Java

```
<// Java 8:
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;

publicclassHttpClient{
  publicstatic String get(String url)throwsIOException{
    HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
    connection.setRequestMethod("GET");
    connection.connect();int responseCode = connection.getResponseCode();
    if (responseCode != 200) {
      throw new IOException("Unexpected response code: " + responseCode);
    }

    return new Scanner(connection.getInputStream()).useDelimiter("\\A").next();
  }
}

// Java 11:
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

publicclassHttpClient {
  public static String get(String url) throws IOException, InterruptedException {
    var client = HttpClient.newHttpClient();
    var request = HttpRequest.newBuilder(URI.create(url)).GET().build();
    var response = client.send(request, HttpResponse.BodyHandlers.ofString());

    return response.body();
  }
}

```

String enhancements:

The `isBlank()` method was introduced in Java 11, so it is not available in Java 8. The isBlank() method checks if a string is empty or contains only whitespace characters. It is more concise and readable than the traditional way of checking if a string is empty using the `trim()` method and then checking if the trimmed string is empty.

Here is an example of how to use the isBlank() method in Java 11:

Java

```
String str = "";

if (str.isBlank()) {
  System.out.println("The string is empty!");
}

```

This code will print "The string is empty!" to the console, because the `str` variable is empty.

In Java 8, you can check if a string is empty using the following code:

Java

```
String str = "";

if (str.trim().isEmpty()) {
  System.out.println("The string is empty!");
}

```

This code is more verbose and less readable than the code using the `isBlank()` method.

Overall, the new features in Java 11 make it easier, more efficient, and more expressive to write Java code. If you are not already using Java 11, I encourage you to upgrade.