Skip to main content

New Features in Java 11

 Java 11 introduced several new features and enhancements. Here are some notable features with examples:

  1. Local-Variable Syntax for Lambda Parameters: Java 11 allows var to be used in lambda parameters, which provides improved readability and conciseness.

Example:

java
// Before Java 11 
someList.forEach((String item) -> { System.out.println(item); });
// With Java 11 
someList.forEach((var item) -> { System.out.println(item); })
  1. HTTP Client (Standard API): Java 11 introduced a new HTTP client API as a replacement for the deprecated HttpURLConnection. It provides a more modern and flexible way to send HTTP requests and handle responses.

Example

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(URI.create("https://api.example.com/users")) .build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body()); } }
  1. Nest-Based Access Control: Java 11 introduced the concept of nest-based access control, allowing access to private members of an outer class from its inner classes and vice versa.


public class OuterClass { private int outerField = 10; public class InnerClass { private int innerField = 20; public int sum() { return outerField + innerField; } } public static void main(String[] args) { OuterClass outer = new OuterClass(); OuterClass.InnerClass inner = outer.new InnerClass(); System.out.println(inner.sum()); // Output: 30 } }

These are just a few examples of the new features introduced in Java 11. Other features include improved performance, Epsilon garbage collector, enhanced security, and more. It's worth noting that Java continues to evolve, and newer versions may introduce additional features and improvements.

Comments

Popular posts from this blog

How I Cracked 3 Job Offers as a Java Developer – My Journey & Key Strategies

 Job hunting can be overwhelming, especially when you’re aiming for a great opportunity that matches your experience and skills. As a Java developer with nearly six years of experience, I recently went through multiple interview processes and ended up receiving six job offers. It wasn’t luck—it was a mix of strategy, preparation, and the right mindset. In this blog, I’ll share my approach, preparation techniques, and lessons learned to help you navigate your job search and ace your interviews. 1. The Turning Point: Why I Started Looking for a Change Like many professionals, I reached a phase where I wanted career growth, better compensation, and challenging projects. While my experience was strong, I realized that just having skills wasn’t enough—I needed to present them effectively in interviews. 2. Building the Right Mindset for Job Hunting Before diving into job applications, I focused on three key aspects: Confidence: Believing in my experience and technical expertise. Clarity:...

Ace Your Java Interview: Top 50 Java Interview Questions & Answers (2025)

  Introduction Java continues to be a top programming language in 2025 , widely used in enterprise applications, microservices, cloud computing, and AI-based systems . If you're preparing for a Java developer interview , you must be well-versed in Core Java, Java 8-21 features, Spring Boot, Microservices, and Cloud technologies . This guide covers the top 50 Java interview questions for freshers and experienced professionals , ensuring you are ready for your next interview! Table of Contents Core Java Interview Questions Java 8, Java 11, and Java 21 Features OOP and Design Patterns Multithreading and Concurrency JVM, Garbage Collection & Memory Management Collections Framework Spring Boot & Microservices Cloud Technologies (AWS, Azure, GCP) Real-World Java Interview Scenarios 1. Core Java Interview Questions Q1: What are the key features of Java? Answer: Platform Independence – Java runs on JVM , making it OS-independent. Object-Oriented – Java follows...

How to Create Immutable Class and Object in Java

How to create Immutable Class and Object in Java - Tutorial Example Writing or creating immutable classes in Java is becoming popular day by day, because of the concurrency and multithreading advantages provided by immutable objects. Immutable objects offer several benefits over a conventional mutable object, especially while creating concurrent Java applications. An immutable object not only guarantees the safe publication of an object’s state but also can be shared among other threads without any external synchronization. In fact, JDK itself contains several immutable classes like String , Integer , and other wrapper classes. For those who don’t know, immutable objects are those whose state cannot be changed once created. A good example is java.lang.String — once created, a String object cannot be modified. Any operation that seems to modify a String object (like trim() , toUpperCase() , etc.) actually results in a new object. What is an Immutable Class in Java? An immutabl...