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)
- What were the main Java 8 features? Lambdas, functional interfaces, method references, default and static interface methods, the Stream API,
Optional, thejava.timeAPI,CompletableFuture, Metaspace replacing PermGen, plusBase64andStringJoiner. - 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,thisrefers to the enclosing instance. - What is a functional interface? An interface with exactly one abstract method, such as
RunnableorComparator.@FunctionalInterfacemakes the compiler enforce it; default and static methods do not count. - Name the core java.util.function interfaces.
Predicate<T>(test),Function<T,R>(apply),Consumer<T>(accept),Supplier<T>(get), plusUnaryOperator,BinaryOperator,BiFunctionand primitive versions such asIntPredicate. - 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). - 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 callA.super.method(); a class method always wins over a default. - What are static interface methods? Utility methods called on the interface, such as
Comparator.comparing(...). Implementing classes do not inherit them. - 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.
- 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. - map versus flatMap?
maptransforms each element one to one.flatMapmaps each element to a stream and flattens the results:lists.stream().flatMap(List::stream).
Intermediate Java 8 questions (11–20)
- Which Collectors come up most?
toList,toSet,toMap(which throwsIllegalStateExceptionon duplicate keys unless you pass a merge function),groupingBy,partitioningByandjoining. - Count employees per department.
emps.stream().collect(Collectors.groupingBy(Employee::getDept, Collectors.counting()))returns aMap<String, Long>. - 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. - What is Optional for? A return type for a value that may be absent. Create with
of(throws on null),ofNullableorempty; transform withmap,flatMapandfilter; finish withorElse,orElseGetororElseThrow(...). Avoid it for fields, parameters and collections. - orElse versus orElseGet?
orElse(x)always evaluatesx, 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. - 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,OffsetDateTimeandInstant(a UTC point on the timeline). - Duration versus Period?
Durationis time-based (seconds and nanoseconds) for instants and times;Periodis date-based (years, months, days):Period.between(start, end). - How do you parse and format dates? With
DateTimeFormatter, which is immutable and thread-safe, unlikeSimpleDateFormat:LocalDate.parse("17/11/2026", DateTimeFormatter.ofPattern("dd/MM/yyyy")). - How do you convert legacy Date objects?
date.toInstant(),Date.from(instant)andinstant.atZone(ZoneId.of("Europe/London")). - 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)
- 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 ascount()runs, and then elements flow through one at a time. - Can you reuse a stream? No. A second terminal operation throws
IllegalStateException. Keep aSupplier<Stream<T>>if you need a fresh one. - Why must captured variables be effectively final? Lambdas capture values, not variables, so reassigning a local would be ambiguous. Mutating an outside collection from
forEachalso breaks under parallel streams; usecollect. - 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.
- How did Comparator improve?
Comparator.comparing(Person::getLastName).thenComparing(Person::getAge).reversed(), plusnullsFirstandnullsLast, replace hand-writtencomparemethods. - 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. - 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. - 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.
- Find the second-highest distinct number.
nums.stream().distinct().sorted(Comparator.reverseOrder()).skip(1).findFirst()returns anOptional<Integer>. - Which Java 8 idioms would you write differently today?
collect(Collectors.toList())becomestoList()(Java 16),!opt.isPresent()becomesopt.isEmpty()(Java 11), and data carriers become records. The table below lists more, but note thatStream.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
| Feature | Added in | Why it matters |
|---|---|---|
Optional.ifPresentOrElse, or, stream; Stream.takeWhile, dropWhile, ofNullable; List.of, Map.of; private interface methods | Java 9 | Fewer isPresent checks and immutable collection literals |
var for local variables; Optional.orElseThrow(); Collectors.toUnmodifiableList | Java 10 | Less boilerplate |
Optional.isEmpty, Predicate.not, String.isBlank, strip, lines, repeat | Java 11 (LTS) | Cleaner filters and string handling |
Collectors.teeing | Java 12 | Two collectors in one pass |
| Switch expressions (14), text blocks (15) | Java 14–15 | Nashorn, added in 8, was removed in 15 |
Records, pattern matching for instanceof, Stream.toList(), mapMulti | Java 16 | Data carriers without boilerplate |
| Sealed classes | Java 17 (LTS) | Closed hierarchies for safe pattern matching |
| Virtual threads, sequenced collections, record patterns, pattern matching for switch | Java 21 (LTS) | Cheap blocking concurrency; exhaustive switches |
Stream gatherers (Stream.gather) | Java 24 | Custom intermediate operations |
| Scoped values, flexible constructor bodies, compact source files and instance main methods, module import declarations | Java 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
| Format | What it usually looks like | How to prepare |
|---|---|---|
| Concept Q&A | Lambdas, functional interfaces, map versus flatMap, Optional, java.time | Answer each with one line of code |
| Stream coding | Group, count, partition, find max per group, first non-repeated character | Write the five scenarios above from memory |
| Code review | Rewrite a loop as a stream, or explain why a parallel stream is wrong | Know 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