OOPs HandbookModern OOP: Streams API, Lambdas, Functional Interfaces & CompletableFuture
Modern OOPAdvanced
12 min read

Modern OOP: Streams API, Lambdas, Functional Interfaces & CompletableFuture

Transforming OOP with functional programming, asynchronous pipelines, and parallel streams.

TM
TestMeMan SDE Curriculum
Updated Sept 2026
Verified for FAANG Interviews
FROM TESTMEMAN•TestMeMan

Mock tests for SSC, Banking, Railways, UPSC & state exams

Real exam pattern, negative marking and a worked solution for every question.

Sponsored Publisher Placement•
ID: ad-top-leaderboard
Executive Summary

Modern OOP integrates functional paradigms to handle big data streaming and asynchronous concurrency.

1. Lambdas & @FunctionalInterface#

• Lambda Expression (Tricky Question 28): A concise, anonymous function representation passed around like data.

• @FunctionalInterface (Tricky Question 42): An interface with exactly ONE abstract method (SAM).

• Core Built-in Interfaces (Tricky Questions 43, 44, 48):

- Predicate: Takes an input and returns a boolean (e.g. `x -> x > 10`).

- Function: Takes an input and returns an output of any type (e.g. `String -> Integer`).

- BiFunction: Takes two arguments and produces a result.

- Supplier: Supplies a result with zero inputs (used for lazy evaluation).

2. Stream vs Collection & Operations#

• Collection vs Stream (Tricky Question 39): Collection is a data structure storing objects in memory. Stream is a sequence of elements supporting pipelined transformations (lazy evaluation).

• map vs flatMap (Tricky Question 41): `map` transforms each element 1-to-1. `flatMap` transforms and flattens nested collections (e.g. `List<List<T>>` into `List<T>`).

• peek vs forEach (Tricky Question 47): `peek` is an intermediate operation for debugging. `forEach` is a terminal operation that triggers stream execution.

• reduce vs collect (Tricky Question 49): `reduce` combines elements into a single aggregate value. `collect` accumulates elements into a mutable data structure (like a List or Map).

• parallelStream vs stream (Tricky Question 45): `stream` processes sequentially on a single thread. `parallelStream` divides workload across multiple CPU cores using the common ForkJoinPool.

Sponsored ContentTestMeMan

Practise placement aptitude on the real test pattern

TCS NQT, Infosys, Wipro, Accenture and Cognizant style mocks with section-wise analysis.

3. CompletableFuture, Optional & Try-With-Resources#

• CompletableFuture (Tricky Question 50): Used for asynchronous programming, allowing chaining, combining, and non-blocking execution of async tasks.

• Optional (Tricky Question 40): Container object that may or may not contain a non-null value, dramatically reducing `NullPointerException` risks.

• Try-with-resources (Tricky Question 30): Ensures resources (files, sockets, database connections) implementing `AutoCloseable` are closed automatically when the try block exits.

• Synchronized keyword (Tricky Question 32): Ensures only one thread can execute a critical section at a time, preventing race conditions.

Test Your Concept Mastery

Verify your retention on: Modern OOP: Streams API, Lambdas, Functional Interfaces & CompletableFuture

Diagnostic Check
Question 1 of 1
What is the main difference between map and flatMap in Java Streams?
Ready for a full proctored assessment?

Take a free quick test on the real exam pattern, with a worked solution for every question.

Launch Mock Test