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:...

The Mysterious Journey of Astronaut Sunita Villms: A Struggle Between Earth and the Unknown

 Astronaut Sunita Williams and her colleague, Barry "Butch" Wilmore, recently returned to Earth after an unexpected nine-month mission aboard the International Space Station (ISS). Originally scheduled for a brief eight-day stay, their mission was extended due to technical issues with the Boeing Starliner spacecraft, leading to a prolonged 286-day duration in space.  Mission Extension and Challenges The mission's extension was primarily due to propulsion problems with the Starliner craft, necessitating their continued presence on the ISS. This unforeseen prolongation presented both physical and psychological challenges for the astronauts. Prolonged exposure to microgravity can lead to muscle atrophy, bone density loss, and other health concerns. To mitigate these effects, astronauts adhere to rigorous exercise regimens while aboard the station.  Health Observations Upon Return Upon their return, noticeable physical changes were observed, particularly with Sunita Williams,...

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...