Home › Blog › Java 8 Interview Questions (2026): 30 Questions on Lambdas, Streams, Optional and java.time

Java 8 Interview Questions (2026): 30 Questions on Lambdas, Streams, Optional and java.time

Java 8 interview questions cover the features that brought functional style to Java in 2014: lambdas, functional interfaces, method references, default methods, the Stream API, Optional and the java.time API. They are still asked in 2026 because nearly all modern Java code is built on them, and good interviewers follow up with what later releases changed.

Java 8 interview questions cover the features that brought functional style to Java in 2014: lambdas, functional interfaces, method references, default methods, the Stream API, Optional and the java.time API. They are still asked in 2026 because nearly all modern Java code is built on them, and good interviewers follow up with what later releases changed. Per openjdk.org, JDK 25 (September 16, 2025) is the latest long-term-support release as of November 17, 2026.

Below are 30 questions by level with short code, five coding scenarios, a table of what Java 9 to 25 added on top of Java 8 (checked against the JDK 25 javadoc and the OpenJDK release pages), and how interviews test this. For the rest of the language, see Java interview questions.

Java 8 interview questions: fundamentals (1–10)

  1. What were the main Java 8 features? Lambdas, functional interfaces, method references, default and static interface methods, the Stream API, Optional, the java.time API, CompletableFuture, Metaspace replacing PermGen, plus Base64 and StringJoiner.
  2. What is a lambda expression? A compact implementation of a functional interface's single method: (a, b) -> a + b. It can capture effectively final local variables, and unlike an anonymous class, this refers to the enclosing instance.
  3. What is a functional interface? An interface with exactly one abstract method, such as Runnable or Comparator. @FunctionalInterface makes the compiler enforce it; default and static methods do not count.
  4. Name the core java.util.function interfaces. Predicate<T> (test), Function<T,R> (apply), Consumer<T> (accept), Supplier<T> (get), plus UnaryOperator, BinaryOperator, BiFunction and primitive versions such as IntPredicate.
  5. What kinds of method reference are there? Static (Integer::parseInt), bound instance (System.out::println), unbound instance of an arbitrary object (String::toUpperCase) and constructor (ArrayList::new).
  6. Why were default methods added? To evolve interfaces without breaking implementations, which is how Collection.stream() was added. If two interfaces supply the same default, the class must override it and can call A.super.method(); a class method always wins over a default.
  7. What are static interface methods? Utility methods called on the interface, such as Comparator.comparing(...). Implementing classes do not inherit them.
  8. What is a stream? A pipeline of operations over a source such as a collection. It stores nothing, is lazy, can be used once and does not modify its source.
  9. Intermediate versus terminal operations? Intermediate operations (filter, map, flatMap, sorted, distinct, limit) return a stream and run lazily. Terminal operations (collect, forEach, reduce, count, findFirst, anyMatch) trigger the work.
  10. map versus flatMap? map transforms each element one to one. flatMap maps each element to a stream and flattens the results: lists.stream().flatMap(List::stream).

Intermediate Java 8 questions (11–20)

  1. Which Collectors come up most? toList, toSet, toMap (which throws IllegalStateException on duplicate keys unless you pass a merge function), groupingBy, partitioningBy and joining.
  2. Count employees per department. emps.stream().collect(Collectors.groupingBy(Employee::getDept, Collectors.counting())) returns a Map<String, Long>.
  3. How does reduce work? An identity, an accumulator and, for parallel streams, a combiner: nums.stream().reduce(0, Integer::sum). For numbers, mapToInt(...).sum() is clearer.
  4. What is Optional for? A return type for a value that may be absent. Create with of (throws on null), ofNullable or empty; transform with map, flatMap and filter; finish with orElse, orElseGet or orElseThrow(...). Avoid it for fields, parameters and collections.
  5. orElse versus orElseGet? orElse(x) always evaluates x, even when a value is present; orElseGet(supplier) calls the supplier only when empty. It matters when the default is expensive, such as a database call.
  6. Why java.time over Date and Calendar? Its types are immutable and thread-safe, months run 1 to 12, and each concept has a clear type: LocalDate, LocalDateTime (no zone), ZonedDateTime, OffsetDateTime and Instant (a UTC point on the timeline).
  7. Duration versus Period? Duration is time-based (seconds and nanoseconds) for instants and times; Period is date-based (years, months, days): Period.between(start, end).
  8. How do you parse and format dates? With DateTimeFormatter, which is immutable and thread-safe, unlike SimpleDateFormat: LocalDate.parse("17/11/2026", DateTimeFormatter.ofPattern("dd/MM/yyyy")).
  9. How do you convert legacy Date objects? date.toInstant(), Date.from(instant) and instant.atZone(ZoneId.of("Europe/London")).
  10. When should you use parallel streams? For large, CPU-bound, stateless work on sources that split well (arrays, ArrayList). Avoid them for I/O, small data, LinkedList, order-sensitive operations and shared mutable state; they run on the common ForkJoinPool.

Experienced and senior Java 8 questions (21–30)

  1. Show that streams are lazy. Stream.of(1, 2, 3).peek(System.out::println).filter(n -> n > 1) prints nothing until a terminal operation such as count() runs, and then elements flow through one at a time.
  2. Can you reuse a stream? No. A second terminal operation throws IllegalStateException. Keep a Supplier<Stream<T>> if you need a fresh one.
  3. Why must captured variables be effectively final? Lambdas capture values, not variables, so reassigning a local would be ambiguous. Mutating an outside collection from forEach also breaks under parallel streams; use collect.
  4. How do you handle checked exceptions in lambdas? The standard functional interfaces declare none, so wrap the call and rethrow an unchecked exception, write a small functional interface that declares the exception, or move the logic into a method that handles it.
  5. How did Comparator improve? Comparator.comparing(Person::getLastName).thenComparing(Person::getAge).reversed(), plus nullsFirst and nullsLast, replace hand-written compare methods.
  6. What does CompletableFuture add? Asynchronous composition: supplyAsync, thenApply, thenCompose, thenCombine, exceptionally. Pass your own executor for blocking work instead of relying on the common pool.
  7. PermGen versus Metaspace? Java 8 removed PermGen. Class metadata now lives in native memory (Metaspace), which grows dynamically and can be capped with -XX:MaxMetaspaceSize.
  8. Interface or abstract class after Java 8? Interfaces can now hold behaviour through default and static methods, but no instance state or constructors. Use an abstract class when subclasses share state or construction logic.
  9. Find the second-highest distinct number. nums.stream().distinct().sorted(Comparator.reverseOrder()).skip(1).findFirst() returns an Optional<Integer>.
  10. Which Java 8 idioms would you write differently today? collect(Collectors.toList()) becomes toList() (Java 16), !opt.isPresent() becomes opt.isEmpty() (Java 11), and data carriers become records. The table below lists more, but note that Stream.toList() returns an unmodifiable list.

Java 8 scenario and troubleshooting questions

Find the first non-repeated character in a string. s.chars().mapToObj(c -> (char) c).collect(groupingBy(Function.identity(), LinkedHashMap::new, counting())), then stream the entries, filter where the count is 1 and take findFirst(). LinkedHashMap keeps insertion order.

Word frequency, sorted by count. Split, then groupingBy(w -> w, counting()), then sort the entries with Map.Entry.comparingByValue(Comparator.reverseOrder()).

Partition numbers into even and odd. nums.stream().collect(partitioningBy(n -> n % 2 == 0)) returns a Map<Boolean, List<Integer>>.

Highest-paid employee per department. groupingBy(Employee::getDept, maxBy(comparing(Employee::getSalary))), which yields Optional values per department.

A toMap call throws IllegalStateException. Duplicate keys. Pass a merge function, toMap(k, v, (a, b) -> a), or use groupingBy if duplicates are meaningful.

What changed after Java 8

FeatureAdded inWhy it matters
Optional.ifPresentOrElse, or, stream; Stream.takeWhile, dropWhile, ofNullable; List.of, Map.of; private interface methodsJava 9Fewer isPresent checks and immutable collection literals
var for local variables; Optional.orElseThrow(); Collectors.toUnmodifiableListJava 10Less boilerplate
Optional.isEmpty, Predicate.not, String.isBlank, strip, lines, repeatJava 11 (LTS)Cleaner filters and string handling
Collectors.teeingJava 12Two collectors in one pass
Switch expressions (14), text blocks (15)Java 14–15Nashorn, added in 8, was removed in 15
Records, pattern matching for instanceof, Stream.toList(), mapMultiJava 16Data carriers without boilerplate
Sealed classesJava 17 (LTS)Closed hierarchies for safe pattern matching
Virtual threads, sequenced collections, record patterns, pattern matching for switchJava 21 (LTS)Cheap blocking concurrency; exhaustive switches
Stream gatherers (Stream.gather)Java 24Custom intermediate operations
Scoped values, flexible constructor bodies, compact source files and instance main methods, module import declarationsJava 25 (LTS)Safer context passing; simpler small programs

Versions are from the JDK 25 javadoc's @since tags and the OpenJDK feature lists for each release.

How Java 8 interviews test this

FormatWhat it usually looks likeHow to prepare
Concept Q&ALambdas, functional interfaces, map versus flatMap, Optional, java.timeAnswer each with one line of code
Stream codingGroup, count, partition, find max per group, first non-repeated characterWrite the five scenarios above from memory
Code reviewRewrite a loop as a stream, or explain why a parallel stream is wrongKnow when a plain loop is clearer
Version follow-up"What changed after Java 8?"Learn the table above, especially 11, 17, 21 and 25

Concurrency follow-ups such as CompletableFuture and virtual threads are in Java multithreading interview questions; framework questions are in Spring Boot interview questions.

Where CoPilot Interview fits

CoPilot Interview is an AI interview assistant. Its free AI mock interview builds Java questions from your résumé and the job description, reads them aloud and scores each spoken answer out of 10, which is a fast way to find the answers above that you know but cannot yet explain cleanly under pressure. The browser demo has 145 practice questions in 10 tracks, scores typed answers out of 10 and needs no signup. The free plan gives 15 minutes a day of live help in sessions of up to 15 minutes, with AI mock interviews included. Paid plans are Standard at $24.99 a month and Pro at $39.99 a month, in the desktop app for Windows 10/11 and macOS 12 or later.

Use it to practice. Online assessments, proctored tests, take-home tasks with rules and AI-led rounds forbid outside help, so prepare for those instead of bringing a tool. For any live interview, follow your employer's rules.

Disclosure: CoPilot Interview is our product, so weigh what we say about it accordingly.

Frequently asked questions

Why are Java 8 questions still asked in 2026?

Streams, lambdas, Optional and java.time are used in almost every modern Java codebase, so interviewers use them to test fluency, then ask what later releases added.

What is the difference between map and flatMap in Java 8?

map turns each element into one new element; flatMap turns each element into a stream and flattens all of them into one stream.

What is the difference between orElse and orElseGet?

orElse always evaluates its argument; orElseGet calls its supplier only when the Optional is empty, which matters for expensive defaults.

Should I prepare Java 8 or Java 21 and 25?

Both: Java 8 features are the foundation, and interviewers commonly ask about records, pattern matching, sealed classes and virtual threads from 16, 17 and 21, with 25 as the newest LTS.

What are common Java 8 coding questions?

Group and count with Collectors, find the second-highest number, first non-repeated character, word frequency, partition even and odd, and max per group.

Practice this interview before the real one

The AI mock interview builds questions from your resume and the job description, reads them aloud and scores each spoken answer out of 10. Included on the free plan.

Start a mock interview