Java Lambda Expressions — Java Technical Interview Questions & Answers

Java Lambda Expressions

Java Lambda Expressions

  • A lambda is a short way to write a small function you can pass around. Shape: (params) -> expression, or { statements }. It implements a functional interface — one abstract method. Example: names.forEach(n -> System.out.println(n));
  • Lambdas make collection and stream code shorter when they stay small. Method references (System.out::println) are even shorter sometimes. Don’t dump huge business logic inside a lambda.
  • Interview line: lambda = concise implementation of a functional interface.
  • Let's take this on the board with one tiny Main class — no extra files. Java Lambda Expressions — output: A then B then C. n -> println(n) is a real lambda — short function passed to forEach. Start from main, go line by line, and stop at each print. That output is the proof for Lambda Expressions.

Technical Interview Tip: Define lambda + show forEach one-liner.

Code Examples for Java Lambda Expressions

Example

import java.util.Arrays;
import java.util.List;

public class Main {
  public static void main(String[] args) {
    List<String> names = Arrays.asList("A", "B", "C");
    names.forEach(n -> System.out.println(n));
  }
}

Java Lambda Expressions — output: A then B then C. n -> println(n) is a real lambda — short function passed to forEach.

How to Explain Java Lambda Expressions to an Interviewer

What is a lambda?

Short function (args) -> body

What does a lambda implement?

A functional interface

Write a forEach lambda.

names.forEach(n -> System.out.println(n))