JDK 11 features | code2java

JDK 11 features

Table of Contents

  • πŸ‘‰ What is JDK 11
  • πŸ‘‰ Why JDK 11 is important
  • πŸ‘‰ Key features introduced in JDK 11
  • πŸ‘‰ Internal working of major features
  • πŸ‘‰ Implementation in Java
  • πŸ‘‰ Summary
  • πŸ‘‰ Interview Questions

πŸ‘‰ What is JDK 11

JDK 11 is a Long-Term Support (LTS) release of Java, which means it is designed for stability and long-term usage in production systems.

After JDK 8, many organizations waited for a solid upgrade path. JDK 11 became that sweet spot β€” stable, modern, and production-ready. πŸš€

It builds on top of the modular system introduced in Java 9 and brings several developer-friendly APIs along with performance improvements.

πŸ‘‰ Why JDK 11 is important

JDK 11 is not about flashy features β€” it’s about practical improvements that you’ll use daily.

πŸ”₯ Why developers love JDK 11:

  • βœ” Long-term support (LTS) β€” safe for production
  • βœ” Removal of legacy clutter (Java EE, CORBA)
  • βœ” Modern HTTP client (no more ugly HttpURLConnection)
  • βœ” Cleaner APIs for String, Files, Optional
  • βœ” JVM and GC improvements

πŸ‘‰ If you’re still on JDK 8, upgrading to JDK 11 is one of the smartest moves you can make.

πŸ‘‰ Key features introduced in JDK 11

Let’s go through the most impactful features β€” not just what they are, but why they matter.

πŸ”₯ 1. New HTTP Client API (Standardized)

Before JDK 11, writing HTTP calls felt painful πŸ˜…
You either used HttpURLConnection or added third-party libraries.

πŸ‘‰ JDK 11 fixes that with a clean, modern HTTP client.

βš™ Internal Working Insight

  • Built on non-blocking I/O (NIO)
  • Uses CompletableFuture for async processing
  • Supports HTTP/2 out of the box
  • Uses fewer threads efficiently

πŸ‘‰ Result: Better scalability and cleaner code.

πŸ’» Implementation in Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class HttpClientExample {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();

        HttpRequest request = HttpRequest.newBuilder()
                .uri(new URI("https://jsonplaceholder.typicode.com/posts/1"))
                .GET()
                .build();

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

        System.out.println("Response: " + response.body());
    }
}

πŸ”₯ 2. String API Enhancements

Small feature, huge impact in real-world coding.

✨ New Methods

  • isBlank()
  • lines()
  • strip(), stripLeading(), stripTrailing()
  • repeat()

βš™ Internal Working Insight

πŸ‘‰ strip() is Unicode-aware, unlike trim().

Internally it uses Character.isWhitespace(), which correctly handles international characters.

πŸ’» Implementation in Java

public class StringMethodsExample {
    public static void main(String[] args) {
        String text = "  Hello Java  ";

        System.out.println(text.isBlank());     // false
        System.out.println(text.strip());       // "Hello Java"
        System.out.println("Java\nPython\nC++".lines().count());
        System.out.println("Hi ".repeat(3));
    }
}

πŸ”₯ 3. var in Lambda Parameters

This looks small, but it’s powerful when combined with annotations.

πŸ€” Why it matters

  • Improves readability
  • Enables annotations inside lambda parameters

πŸ’» Implementation in Java

import java.util.List;

public class VarLambdaExample {
    public static void main(String[] args) {
        List<String> names = List.of("Java", "Python", "Go");

        names.forEach((var name) -> System.out.println(name));
    }
}

πŸ‘‰ You can now write things like (@NotNull var name).

πŸ”₯ 4. Files API Enhancements

File handling is now much cleaner. No more boilerplate streams.

✨ New Methods

  • readString()
  • writeString()

βš™ Internal Working Insight

Internally these methods use buffered streams and optimized byte handling, which improves performance and reduces code complexity.

πŸ’» Implementation in Java

import java.nio.file.Files;
import java.nio.file.Path;

public class FileExample {
    public static void main(String[] args) throws Exception {
        Path path = Path.of("sample.txt");

        Files.writeString(path, "Hello from JDK 11");
        String content = Files.readString(path);

        System.out.println(content);
    }
}

πŸ”₯ 5. Optional Enhancements

Optional becomes more expressive and less verbose.

✨ New Methods

  • isEmpty()
  • ifPresentOrElse()
  • or()

πŸ’» Implementation in Java

import java.util.Optional;

public class OptionalExample {
    public static void main(String[] args) {
        Optional<String> value = Optional.ofNullable(null);

        value.ifPresentOrElse(
                v -> System.out.println("Value: " + v),
                () -> System.out.println("No value present")
        );
    }
}

πŸ‘‰ No more repetitive null checks.

πŸ”₯ 6. Nest-Based Access Control

This is an under-the-hood improvement that many developers overlook.

βš™ Internal Working Insight

Before JDK 11:

  • Compiler generated synthetic methods to access private members

After JDK 11:

  • JVM directly allows access between nested classes
  • Cleaner bytecode
  • Better performance

πŸ’» Implementation in Java

class Outer {
    private String message = "Hello";

    class Inner {
        void print() {
            System.out.println(message);
        }
    }
}

πŸ”₯ 7. Removal of Java EE and CORBA Modules

JDK 11 removes outdated modules like:

  • java.xml.bind (JAXB)
  • java.xml.ws (JAX-WS)
  • CORBA

πŸ€” Why this matters

To reduce JDK size and push developers toward external dependency management using Maven or Gradle.

πŸ”₯ 8. Z Garbage Collector (ZGC) πŸš€

One of the most exciting JVM improvements.

βš™ Internal Working Insight

  • Uses colored pointers
  • Performs concurrent compaction
  • Maintains very low pause times (<10ms)

πŸ‘‰ Ideal for large-scale, low-latency systems.

πŸ”₯ 9. Flight Recorder (Open Source)

Java Flight Recorder is now available without commercial restrictions.

πŸ“Š Why it’s useful

  • Low-overhead profiling
  • Production monitoring
  • Deep JVM insights

πŸ‘‰ Implementation in Java

Here’s a combined example using multiple JDK 11 features:

import java.net.URI;
import java.net.http.*;
import java.nio.file.*;
import java.util.*;

public class JDK11Demo {
    public static void main(String[] args) throws Exception {

        // πŸ”₯ String enhancement
        String input = "  Java  ";
        System.out.println(input.strip().repeat(2));

        // πŸ”₯ Optional enhancement
        Optional<String> optional = Optional.of("JDK 11");
        optional.ifPresentOrElse(System.out::println, () -> System.out.println("Empty"));

        // πŸ”₯ File API
        Path path = Path.of("demo.txt");
        Files.writeString(path, "Hello JDK 11");
        System.out.println(Files.readString(path));

        // πŸ”₯ HTTP Client
        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
                .uri(new URI("https://jsonplaceholder.typicode.com/todos/1"))
                .GET()
                .build();

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

πŸ‘‰ Summary

JDK 11 focuses on real-world developer productivity and performance.

πŸ”₯ Key takeaways:

  • Modern HTTP client replaces legacy APIs
  • Cleaner APIs for String, Files, and Optional
  • JVM improvements like ZGC and nest-based access
  • Removal of outdated modules
  • Stable and production-ready LTS release

πŸ‘‰ If you’re serious about Java development, JDK 11 is a must-have upgrade.

Also, if you want to understand how Java collections work internally, check this:
https://code2java.com/internal-implementation-of-hashmap/

πŸ‘‰ Interview Questions

πŸ‘‰ 1. What are the major features introduced in JDK 11?
πŸ‘‰ 2. How does the new HTTP Client work internally?
πŸ‘‰ 3. What is the difference between trim() and strip()?
πŸ‘‰ 4. Explain Z Garbage Collector and its advantages.
πŸ‘‰ 5. Why were Java EE modules removed in JDK 11?
πŸ‘‰ 6. What is nest-based access control?
πŸ‘‰ 7. How does Files.readString() improve file handling?
πŸ‘‰ 8. What new methods were added in Optional?

Related Posts

  • Abstract Class In JAVA

    Hello Friends, This tutorial is for all the Java followers. One of the best feature that is widely used is the term ‘Abstract’. This term can be used as either class or a simple method. An abstract method is any method that is just declared but not instantiated. In other words one can just create…

  • Threads in Java.

    Hello Friends, This is the tutorial for the java developers. One of the most significance feature of core java is Threading. Threading deals with the processing of Threads in a single java program. Let us learn what actually are Threads. *What are Threads? Threads are independently running processes that are isolated from each other upto…

  • Collections In Java.

    Hello friends, Welcome to another tutorial for java followers. You all may have heard about Collections, it is one of the amazing feature in java. Collections are the object for the group of elements, these elements are nothing but the different data structures like as Array Lists, Linked Lists, Vectors, Hash tables,Hash List, Trees, Hash…

  • Maven Installation.

    Hello Friends, This is one of my tutorial for installation of Maven on windows. Maven is a software project management tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information. Maven is an open source community and is a…

  • Jira Plugin Deployment.

    Hello Friends, This is one of the most important tutorial for all the jira developers. You may have heard about the plugins in jira which is a simple Java Archive File with .jar extension. This JAR file contains the class files and auxiliary resources associated with the applications. In Jira we can use Eclipse IDE…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.