Chaturmind
LearnDSASystem DesignInterview PrepDevOpsEngineering GrowthBlog
Start learning
Chaturmind

Structured learning paths for engineers who want to go deep. Written by practitioners.

Learn

  • Java
  • DSA
  • System Design
  • Spring Boot
  • AI / ML
  • DevOps
  • Engineering Growth
  • Java Interview Prep

Company

  • Blog
  • Contact

Legal

  • Privacy Policy
  • Terms of Service

© 2026 Chaturmind. All rights reserved.

Built for engineers who want to go deep.


← Java Interview Prep: Fresher to 2 Years

Java Basics, JVM & Memory

  • JDK, JRE, JVM & the main Method — Interview Questions
  • JVM Memory & Garbage Collection — Interview Questions
  • Data Types, Wrapper Classes & Equality — Interview Questions

Object-Oriented Programming

  • Classes, Objects, Packages & Access Modifiers — Interview Questions
  • Inheritance, Composition, this & super — Interview Questions
  • Polymorphism, Overloading & Overriding — Interview Questions
  • Abstraction, Interfaces & Encapsulation — Interview Questions
  • Constructors, Singleton, Anonymous Classes & Immutability — Interview Questions
  • Design Patterns & SOLID Basics — Interview Questions

Strings, Keywords, Exceptions & Serialization

  • Strings, String Pool, StringBuilder & StringBuffer — Interview Questions
  • static & final Keywords — Interview Questions
  • Exceptions, Generics, Enums & Reflection — Interview Questions
  • Serialization & transient — Interview Questions

Collections Framework

  • Collections Framework Basics — Interview Questions
  • HashMap, HashSet & TreeMap Internals — Interview Questions

Multithreading Basics

  • Threads, Synchronization & volatile Basics — Interview Questions

Java 8+ & Stream API

  • Java 8 to Java 21 Features — Interview Questions
  • Stream API Coding Questions (Part 1) — Interview Questions
  • Stream API Coding Questions (Part 2) — Interview Questions

Coding Round Programs

  • Classic Number & String Programs — Interview Questions
  • String & Collection Programs — Interview Questions
  • Array & String Problem Solving — Interview Questions

Spring Framework Core

  • Spring IoC, Dependency Injection & Beans — Interview Questions
  • Spring Injection Types, Scopes, Profiles & WebFlux — Interview Questions

Spring Boot Essentials

  • Spring Boot Fundamentals — Interview Questions
  • Spring Boot Runners, Servers & Configuration — Interview Questions
  • Spring Boot Controllers, Profiles, Actuator & DevTools — Interview Questions
  • Spring Boot Testing, Exceptions & Auto-Configuration — Interview Questions
  • REST APIs, Swagger, Embedded Servers & Key Annotations — Interview Questions

Spring MVC

  • Spring MVC Architecture & DispatcherServlet — Interview Questions
  • Spring MVC Request Mapping & Controllers — Interview Questions
  • Spring MVC Forms, Views & Interceptors — Interview Questions
  • Spring MVC Exceptions, Security & Dependency Injection — Interview Questions
  • Spring MVC Data Binding, Static Resources & Path Variables — Interview Questions
  • Spring MVC i18n, Testing, File Uploads & Scaling — Interview Questions

Hibernate & Spring Data JPA

  • Hibernate & JPA Core Concepts — Interview Questions
  • Hibernate Performance, Mapping & Scenarios — Interview Questions

SQL

  • SQL Basics, Keys, Normalization & Transactions — Interview Questions
  • SQL Joins, Triggers, Procedures, Functions & Indexes — Interview Questions
  • SQL "Difference Between" Questions — Interview Questions
  • SQL Query Writing (Part 1) — Interview Questions
  • SQL Query Writing (Part 2) — Interview Questions

Microservices Basics

  • Microservices, API Gateway & Communication — Interview Questions
  • Service Discovery, Data Consistency & Deployment — Interview Questions
  • Microservices Monitoring, Security & Resilience — Interview Questions

Maven & Git

  • Maven — Interview Questions
  • Git — Interview Questions
Chaturmind
← Java Interview Prep: Fresher to 2 Years

Java Basics, JVM & Memory

  • JDK, JRE, JVM & the main Method — Interview Questions
  • JVM Memory & Garbage Collection — Interview Questions
  • Data Types, Wrapper Classes & Equality — Interview Questions

Object-Oriented Programming

  • Classes, Objects, Packages & Access Modifiers — Interview Questions
  • Inheritance, Composition, this & super — Interview Questions
  • Polymorphism, Overloading & Overriding — Interview Questions
  • Abstraction, Interfaces & Encapsulation — Interview Questions
  • Constructors, Singleton, Anonymous Classes & Immutability — Interview Questions
  • Design Patterns & SOLID Basics — Interview Questions

Strings, Keywords, Exceptions & Serialization

  • Strings, String Pool, StringBuilder & StringBuffer — Interview Questions
  • static & final Keywords — Interview Questions
  • Exceptions, Generics, Enums & Reflection — Interview Questions
  • Serialization & transient — Interview Questions

Collections Framework

  • Collections Framework Basics — Interview Questions
  • HashMap, HashSet & TreeMap Internals — Interview Questions

Multithreading Basics

  • Threads, Synchronization & volatile Basics — Interview Questions

Java 8+ & Stream API

  • Java 8 to Java 21 Features — Interview Questions
  • Stream API Coding Questions (Part 1) — Interview Questions
  • Stream API Coding Questions (Part 2) — Interview Questions

Coding Round Programs

  • Classic Number & String Programs — Interview Questions
  • String & Collection Programs — Interview Questions
  • Array & String Problem Solving — Interview Questions

Spring Framework Core

  • Spring IoC, Dependency Injection & Beans — Interview Questions
  • Spring Injection Types, Scopes, Profiles & WebFlux — Interview Questions

Spring Boot Essentials

  • Spring Boot Fundamentals — Interview Questions
  • Spring Boot Runners, Servers & Configuration — Interview Questions
  • Spring Boot Controllers, Profiles, Actuator & DevTools — Interview Questions
  • Spring Boot Testing, Exceptions & Auto-Configuration — Interview Questions
  • REST APIs, Swagger, Embedded Servers & Key Annotations — Interview Questions

Spring MVC

  • Spring MVC Architecture & DispatcherServlet — Interview Questions
  • Spring MVC Request Mapping & Controllers — Interview Questions
  • Spring MVC Forms, Views & Interceptors — Interview Questions
  • Spring MVC Exceptions, Security & Dependency Injection — Interview Questions
  • Spring MVC Data Binding, Static Resources & Path Variables — Interview Questions
  • Spring MVC i18n, Testing, File Uploads & Scaling — Interview Questions

Hibernate & Spring Data JPA

  • Hibernate & JPA Core Concepts — Interview Questions
  • Hibernate Performance, Mapping & Scenarios — Interview Questions

SQL

  • SQL Basics, Keys, Normalization & Transactions — Interview Questions
  • SQL Joins, Triggers, Procedures, Functions & Indexes — Interview Questions
  • SQL "Difference Between" Questions — Interview Questions
  • SQL Query Writing (Part 1) — Interview Questions
  • SQL Query Writing (Part 2) — Interview Questions

Microservices Basics

  • Microservices, API Gateway & Communication — Interview Questions
  • Service Discovery, Data Consistency & Deployment — Interview Questions
  • Microservices Monitoring, Security & Resilience — Interview Questions

Maven & Git

  • Maven — Interview Questions
  • Git — Interview Questions
HomeLearnJava Interview PrepJava Interview Prep: Fresher to 2 YearsJava 8+ & Stream API
✓ FreeBeginner· 8 min read

Java 8 to Java 21 Features — Interview Questions

Functional interfaces, why lambdas, streams and Optional arrived, filter vs map, intermediate vs terminal operations, loops vs streams, interface changes, String.join, and the headline features of Java 11, 17 and 21.

Published September 25, 2026


How to use this lesson

"What's new in Java 8?" is asked of nearly every Java candidate. Increasingly, it's followed by "and in 11, 17, 21?". Know which features are final in which LTS release. Mixing up preview and final features is a common, avoidable mistake.

Q1. What is a functional interface?

Short answer: An interface with exactly one abstract method (a SAM, "single abstract method"). Its instances can be created with lambdas, method references or constructor references. Examples: Runnable, Comparator<T>, Function<T,R>, Predicate<T>, Supplier<T>, Consumer<T>.

@FunctionalInterface
interface DiscountRule { BigDecimal apply(BigDecimal price); }

DiscountRule tenPercent = p -> p.multiply(new BigDecimal("0.90"));
Function<String, Integer> length = String::length;          // method reference
Supplier<List<String>> newList = ArrayList::new;            // constructor reference

Key points to cover:

  • @FunctionalInterface is optional. It makes the compiler reject a second abstract method.
  • default and static methods don't count towards the single method, and nor do methods that redeclare Object methods (such as equals).

Learn it in depth → Lambda Expressions

Q2. Can a functional interface extend another interface? What are the advantages of functional interfaces?

Short answer: Yes, as long as the result still has exactly one abstract method in total. It can extend an interface that has only default or static methods, or one whose single abstract method is the same one it declares. (UnaryOperator<T> extends Function<T,T>, for example.)

interface Named { default String label() { return "rule"; } }
@FunctionalInterface
interface PricingRule extends Named { BigDecimal price(Order o); }    // still one abstract method: valid

Key points to cover:

  • Advantages:
    • Concise behaviour-passing with lambdas, instead of anonymous classes.
    • They're the foundation of the Stream API and CompletableFuture.
    • Easy composition (andThen, compose, Predicate.and).
    • Strategies become simple values.

Common trap: many answer sheets say "no, it can't extend another interface". It can. What it can't end up with is two abstract methods.

Q3. What were the major features of Java 8?

Short answer:

  • Lambda expressions and method references.
  • Functional interfaces (java.util.function).
  • The Stream API.
  • Default and static methods in interfaces.
  • Optional.
  • The new Date-Time API (java.time).
  • Also: CompletableFuture, StringJoiner/String.join, collection methods (forEach, removeIf, Map.merge), Nashorn, and Metaspace replacing PermGen.

Learn it in depth → Streams API

Q4. Why were Optional, lambdas and the Stream API introduced?

Short answer:

  • Lambdas: to pass behaviour as data concisely, instead of writing anonymous classes. That was essential for parallel and functional-style libraries.
  • Streams: to express bulk operations on collections declaratively (what, not how), with pipelines that can be lazy and easily parallelised.
  • Optional: to make "this may have no value" explicit in method signatures, reducing accidental NullPointerExceptions.
Optional<Customer> customer = repository.findByEmail(email);
String city = customer.map(Customer::address).map(Address::city).orElse("Unknown");

Key points to cover:

  • Use Optional as a return type. Don't use it for fields, parameters or collections. Never call get() without checking; use orElse, orElseThrow or map.

Learn it in depth → Optional

Q5. What's the difference between filter and map in streams?

Short answer: filter(predicate) keeps or drops elements, so the stream may get smaller but the element type stays the same. map(function) transforms every element into something else, so the stream keeps the same size but the type may change.

List<String> activeEmails = users.stream()
        .filter(User::isActive)        // Stream<User>, fewer elements
        .map(User::email)              // Stream<String>, one email per remaining user
        .toList();

Key points to cover:

  • flatMap maps each element to a stream, and flattens the results. For example, one order becomes many order lines.

Q6. What were the new features in Java 11 (LTS)?

Short answer:

  • The standard HTTP Client (java.net.http, supporting HTTP/2 and async).
  • var in lambda parameters.
  • Running single-file programs directly (java Hello.java).
  • New String methods: isBlank(), strip(), stripLeading(), stripTrailing(), lines(), repeat().
  • Files.readString/writeString, and Optional.isEmpty().
  • The Epsilon (no-op) GC, and ZGC as an experimental collector.
  • Flight Recorder was open-sourced.

Key points to cover:

  • Removals: Java EE and CORBA modules (JAXB, JAX-WS), and JavaFX from the JDK. Many Java 8 → 11 migrations stumble over missing JAXB.

Q7. What were the new features in Java 17 (LTS)?

Short answer:

  • Sealed classes became final in 17.
  • Features finalised between Java 12 and 16, which 17 is the first LTS to include:
    • records;
    • pattern matching for instanceof;
    • text blocks;
    • switch expressions.
  • Also: strong encapsulation of JDK internals, new random-number generators, and the macOS/AArch64 port.

Common trap: listing "pattern matching for switch" and the "Foreign Function & Memory API" as Java 17 features. In 17 they were a preview and an incubator module respectively. Pattern matching for switch became final in Java 21, and FFM in Java 22.

Learn it in depth → Sealed Classes

Q8. What were the new features in Java 21 (LTS)?

Short answer:

  • Virtual threads (Project Loom).
  • Sequenced collections (getFirst(), getLast(), reversed()).
  • Record patterns.
  • Pattern matching for switch.
  • Generational ZGC.

Structured concurrency and scoped values were still previews in 21.

String describe(Shape s) {
    return switch (s) {                                  // exhaustive over a sealed hierarchy
        case Circle c        -> "circle r=" + c.radius();
        case Rectangle(var w, var h) -> "rect " + w + "x" + h;   // record pattern
    };
}

Key points to cover:

  • Java 25 (September 2025) is the latest LTS. It finalised scoped values, compact source files and instance main methods, and flexible constructor bodies.

Learn it in depth → Virtual Threads

Q9. Which is faster, a traditional for loop or a stream?

Short answer: For simple operations on small or medium collections, a plain loop is usually a little faster. There's no pipeline set-up, no lambda calls, and no boxing. The JIT narrows the gap considerably, though. For most business code, the difference is negligible compared with I/O.

Key points to cover:

  • Boxed streams (Stream<Integer>) are slower than primitive streams (IntStream). Use mapToInt for numeric work.
  • Parallel streams can help with large, CPU-bound, easily split workloads, but they hurt for small collections, blocking I/O, or order-dependent operations.

Q10. When would you use a loop, and when a stream?

Short answer: Use a stream for declarative data transformations (filter, map, group, aggregate), where readability matters. Use a loop when you need early exit with complex conditions, checked exceptions, index manipulation, updates to several variables, or maximum performance in a hot path.

Q11. What are intermediate and terminal operations?

Short answer: Intermediate operations (filter, map, sorted, distinct, limit) return a new stream and are lazy: nothing runs until a terminal operation is called. Terminal operations (collect, toList, forEach, reduce, count, findFirst) trigger processing, and produce a result or a side effect. After that, the stream is consumed.

Stream<String> s = names.stream().filter(n -> { System.out.println("check " + n); return n.startsWith("A"); });
// nothing printed yet: lazy
s.findFirst();   // now it runs, and stops at the first match (short-circuit)

Key points to cover:

  • sorted and distinct are stateful intermediate operations. findFirst, anyMatch and limit short-circuit.
  • Reusing a consumed stream throws an IllegalStateException.

Learn it in depth → Streams API

Q12. How did interfaces change from Java 7 to Java 8 (and 9)?

Short answer: In Java 7, interfaces could have only abstract methods and constants. Java 8 added default methods (inherited, overridable implementations) and static methods. Java 9 added private methods, so default methods can share helper code.

Learn it in depth → Interfaces and Abstract Classes

Q13. What is String.join() used for?

Short answer: It concatenates strings with a delimiter, without manual loops or trailing separators.

String.join(", ", List.of("Java", "Spring", "SQL"));     // "Java, Spring, SQL"
String.join("/", "api", "v1", "orders");                // "api/v1/orders"
names.stream().collect(Collectors.joining(", ", "[", "]"));   // with a prefix and suffix

Follow-up questions this topic invites — and their answers

Q: What are the four core functional interfaces? A: Supplier<T> (no input → T), Consumer<T> (T → nothing), Function<T,R> (T → R) and Predicate<T> (T → boolean), plus their Bi… and primitive variants (IntPredicate, ToLongFunction, …).

Q: What does "effectively final" mean for lambdas? A: A lambda can use local variables from its enclosing scope only if they are never reassigned. The lambda captures a copy of the value, so allowing mutation would be confusing and unsafe across threads.

Q: map vs flatMap on Optional? A: map wraps the function's result in an Optional. flatMap expects the function to return an Optional already, which avoids Optional<Optional<T>>.

Q: What replaced Date and Calendar? A: The immutable, thread-safe java.time API: LocalDate, LocalDateTime, ZonedDateTime, Instant, Duration, Period and DateTimeFormatter.

Previous

Threads, Synchronization & volatile Basics — Interview Questions

Next

Stream API Coding Questions (Part 1) — Interview Questions

AI Tutor

Lesson: Java 8 to Java 21 Features — Interview Questions

Quick actions

AI responses can be inaccurate. Verify critical information.