Junior — Middle
How have you used JDK 11 in your projects and what features did you work with?
sobes.tech AI
Answer from AI
In projects using JDK 11, I utilized new features and improvements introduced in this version:
- Local variables with var: you can use
varto declare local variables with the type inferred by the compiler. - New methods in standard APIs: for example, methods in String (isBlank, lines, repeat), Optional (ifPresentOrElse), Collection (toArray(IntFunction)), and others.
- HTTP Client API: a new standard HTTP client for asynchronous and synchronous requests.
- Flight Recorder and JFR Event Streaming: for monitoring and profiling applications.
Example of using the new HTTP client:
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://example.com"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
JDK 11 also supports running single-line Java scripts and improved Unicode handling.