Course contents

Functional Java & Streams: complete interview question bank

Premium36 questions · 36 what-if follow-ups

This is the Functional Java and Streams pass I would do before a Java backend interview. It pulls together the questions that look like syntax on the surface, but really test whether you understand target typing, pipeline execution, collectors, ordering, parallel costs and coding trade-offs.

Use it like a mock interview. Read the question, say your answer out loud first, then open the model answer and check whether you led with the right default, the trade-off and the edge case.

Treat this as the final pass after the topic pages: lambdas, stream basics, stream operations and stream puzzles.

Lambdas & functional interfaces

6 questions

Lambda questions check whether you can connect the short syntax to the interface contract, capture rules and runtime behavior instead of treating lambdas as magic callbacks.

Question 1. ConceptWarm-upAsked very often

What is a functional interface, and why would you add @FunctionalInterface?

Tests SAM rule, default methods, annotation

Show answerHide answer1 follow-up

Model answer

A functional interface has exactly one abstract method, so a lambda or method reference has one target shape to implement. Default and static methods do not count against that rule. @FunctionalInterface is optional, but it makes the compiler protect the contract if someone later adds a second abstract method.

This is the core idea in Lambdas and functional interfaces.

How I’d say it in the interview

"The annotation doesn't create lambda behavior. It documents and enforces the one-abstract-method contract."

Signals depth

Mentioning that Java reused interfaces rather than adding a separate function type.

Red flags

Saying any interface used by a lambda is automatically functional.

Follow-ups interviewers ask next

  1. What if the interface has one abstract method and three default methods?

    It is still functional because defaults already have bodies.

Question 2. ConceptCoreAsked very often

Why does var f = s -> s.length() not compile?

Tests target typing, poly expressions, lambda types

Show answerHide answer1 follow-up

Model answer

A lambda needs a target type from the surrounding context. var asks the initializer for its standalone type, but the lambda does not have one by itself. Assign it to Function<String, Integer>, ToIntFunction<String>, or another explicit functional interface.

Review Lambdas and functional interfaces for the target-typing model.

How I’d say it in the interview

"The lambda text is not born as a Function. The target type tells the compiler what s is and what the return value must be."

Signals depth

Calling lambdas poly expressions and mentioning primitive functional interfaces when boxing matters.

Red flags

Assuming the compiler can infer String from s.length() alone in every context.

Follow-ups interviewers ask next

  1. What if two overloads accept similar functional interfaces?

    The call may be ambiguous. Use a typed variable, a cast, or a clearer API.

Question 3. What does it print?CoreCommonly asked

How is this inside a lambda different from this inside an anonymous class?

Tests lexical scope, anonymous classes, receiver binding

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 4. ConceptCoreAsked very often

Why must a local variable captured by a lambda be final or effectively final?

Tests capture, stack frame, reassignment

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 5. ScenarioCoreCommonly asked

When would you prefer a lambda over a method reference?

Tests readability, method references, captured constants

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 6. DesignCoreCommonly asked

How do you compose predicates without turning the code into a unreadable chain?

Tests Predicate.and, naming, composition

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Stream basics

6 questions

Stream basics questions test whether you can see the source, the lazy pipeline, the terminal operation and the one-shot nature of streams.

Question 7. ConceptWarm-upAsked very often

What is a stream, and how is it different from a collection?

Tests source, pipeline, storage

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 8. ConceptCoreAsked very often

What does laziness mean in a stream pipeline?

Tests laziness, terminal operation, vertical execution

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 9. What does it print?SeniorCommonly asked

Why can count() skip a peek on Java 21?

Tests SIZED, count optimization, side effects

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 10. DebuggingCoreAsked very often

Why does reusing a stream throw IllegalStateException?

Tests one-shot streams, terminal operation, supplier pattern

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 11. ScenarioCoreAsked very often

When would you choose findFirst over findAny?

Tests encounter order, short-circuiting, parallel streams

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 12. ConceptCoreCommonly asked

Why use IntStream instead of Stream<Integer> for numeric work?

Tests primitive streams, boxing, numeric terminals

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Operations with streams

6 questions

Operations questions check whether you choose the right stage for the shape change and understand where ordering, state and side effects sneak in.

Question 13. ConceptCoreAsked very often

Explain map versus flatMap using orders and line items.

Tests one-to-one, one-to-many, nested streams

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 14. ConceptCoreCommonly asked

When are skip, limit, takeWhile and dropWhile the right tools?

Tests slicing, prefix operations, encounter order

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 15. ScenarioCoreCommonly asked

How do you sort by two fields and keep distinct business keys?

Tests Comparator, distinct, distinctBy trade-off

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 16. What does it print?SeniorAsked very often

What is wrong with reduce(10, Integer::sum) on a parallel stream?

Tests reduce identity, associativity, parallel partitions

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 17. DebuggingCoreAsked very often

Why is mutating an ArrayList inside parallelStream().forEach a bug?

Tests side effects, non-interference, parallel forEach

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 18. DebuggingSeniorCommonly asked

Why can distinct().limit(3) hang on an infinite stream?

Tests infinite streams, stateful operations, operation order

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Collectors

6 questions

Collectors questions test whether you can build result containers deliberately: maps, grouped data, immutable results, downstream collectors and custom accumulation.

Question 19. ConceptCoreAsked very often

When would you use toList(), Collectors.toList() and toUnmodifiableList()?

Tests list collectors, mutability, null policy

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 20. ConceptCoreAsked very often

Explain groupingBy with a downstream collector.

Tests classifier, downstream collector, map supplier

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 21. DebuggingCoreAsked very often

How do you handle duplicate keys with Collectors.toMap?

Tests duplicate keys, merge function, map supplier

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 22. ScenarioCoreCommonly asked

What does collectingAndThen buy you?

Tests finishing step, immutable results, maxBy unwrap

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 23. DesignSeniorSometimes asked

When would you write a custom collector?

Tests supplier, accumulator, combiner, finisher

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 24. ConceptCoreCommonly asked

How do immutable collection collectors differ from unmodifiable views?

Tests immutable collections, defensive copying, views

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Parallel streams & Spliterator

6 questions

Parallel stream questions are judgment questions. They test whether you understand splitting, the common pool, ordering costs and why parallel does not mean automatically faster.

Question 25. ScenarioCoreAsked very often

When does a parallel stream usually help?

Tests CPU-bound work, splitting, overhead

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 26. ConceptSeniorCommonly asked

Why can ordered parallel operations be slower?

Tests encounter order, coordination, forEachOrdered

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 27. ScenarioSeniorCommonly asked

What is the common fork-join pool issue with parallel streams?

Tests common pool, blocking, isolation

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 28. ConceptCoreCommonly asked

What does a Spliterator do?

Tests traversal, splitting, characteristics

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 29. ConceptSeniorSometimes asked

Why are ArrayList and LinkedList different sources for parallel streams?

Tests splitting cost, locality, source shape

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 30. DebuggingSeniorCommonly asked

What makes a collector safe or unsafe for parallel collection?

Tests collector combiner, shared state, characteristics

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Stream coding problems

6 questions

Coding-problem questions test whether you can name the pattern first: count, group, rank, flatten, zip, partition or switch to a loop when a stream makes the algorithm worse.

Question 31. CodingCoreAsked very often

Find the second-highest distinct salary.

Tests distinct, sorted, skip, Optional

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 32. CodingCoreAsked very often

Count word frequency and return it sorted by count descending.

Tests groupingBy, counting, sorted entries, LinkedHashMap

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 33. CodingCoreAsked very often

Group employees by department and average salary.

Tests groupingBy, averagingInt, map supplier

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 34. CodingCoreCommonly asked

Find the first non-repeating character in a string.

Tests LinkedHashMap, codePoints, ordering

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 35. CodingSeniorSometimes asked

Zip two lists by index.

Tests IntStream.range, indices, list access cost

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Question 36. DesignSeniorCommonly asked

When should you abandon a stream solution in a coding problem?

Tests algorithm choice, running state, merge sorted lists

Model answer, how to say it, 1 follow-up: unlock with the Java Pass

Premium question set

Keep reading with the Java Pass

The rest of this question set is part of Java One-Stop Interview Prep: in-depth explanations, diagrams, model answers and how to say them in the interview.

From ₹199 · one-time payment · No auto-renewal

Topic question sets in Functional Java & Streams