Here are 100 Java 8 interview questions, organized by level:
Beginner (30 Questions)
-
What are the major features introduced in Java 8?
-
What is a lambda expression? Write its basic syntax.
-
What makes an interface a functional interface, and how do you annotate one?
-
What are default methods in interfaces, and why were they added?
-
How do static methods in interfaces work? Give an example.
-
What is the Stream API, and why use it over traditional loops?
-
Explain the difference between intermediate and terminal operations in a Stream.
-
How do you filter elements in a Stream?
-
How do you map elements in a Stream?
-
How do you sort elements in a Stream pipeline?
-
How do you collect Stream elements into a
ListusingCollectors.toList()? -
What is the Optional class, and how does it help avoid null checks?
-
How do you create an
Optionalwith and without a value? -
How do you use
Optional.ifPresent()? -
What’s the difference between
Optional.orElse()andorElseGet()? -
Name the main classes introduced in the Date/Time API (java.time).
-
How do you get the current date with
LocalDate.now()? -
How do you parse a string into a
LocalDate? -
How do you format a
LocalDateto a string? -
What is the difference between
LocalDate,LocalTime, andLocalDateTime? -
What are Duration and Period used for?
-
How do you measure the duration between two
Instants? -
What is a method reference? List three types with examples.
-
How do you perform Base64 encoding and decoding in Java 8?
-
What’s the purpose of the
java.util.functionpackage? Name three interfaces it provides. -
How do you create a Stream from a Collection?
-
How do you create a Stream from an array?
-
What does
Collectors.joining()do? Give an example. -
How do you implement
Runnableusing a lambda expression? -
What is
Stream.of()and when would you use it?
Medium (40 Questions)
-
Explain the difference between
map()andflatMap()in Streams. -
What is the
reduce()operation? Provide a sample use-case. -
How do you group elements using
Collectors.groupingBy()? -
How do you partition a Stream with
Collectors.partitioningBy()? -
Outline the steps to build a custom Collector.
-
How do you create infinite Streams with
Stream.iterate()andStream.generate()? -
When and how would you use
parallelStream()? What should you watch out for? -
What is a Spliterator, and how does it relate to Streams?
-
How do you manually split work with a Spliterator?
-
What
Spliteratorcharacteristics affect parallel performance? -
Give examples of short-circuiting Stream operations.
-
What’s the difference between
forEach()andforEachOrdered()? -
How can you handle exceptions inside a lambda?
-
How do you chain multiple
Comparators? -
What do
Comparator.nullsFirst()andnullsLast()do? -
How do you convert a Stream to a
Mapwith collectors? -
What happens if you collect into a concurrent map?
-
How do you use
Collector.of()to create a stateful collector? -
How does
Collectors.collectingAndThen()work? -
Explain
Optional.map()vs.Optional.flatMap(). -
How and why use
Optional.orElseThrow()? -
How do you use
DateTimeFormatterwith custom patterns? -
How do you convert between
LocalDateTimeand a different time zone (ZonedDateTime)? -
How do you convert legacy
java.util.Datetojava.time.LocalDate? -
How do you combine multiple
CompletableFutures? -
What’s the difference between
thenApply(),thenCompose(), andthenCombine()? -
How do you handle errors in a
CompletableFuturechain? -
What are
CompletableFuture.allOf()andanyOf()for? -
How do default methods resolve conflicts when two interfaces define the same method?
-
How do you use
LongAdderandLongAccumulatorfor high-throughput counters? -
Compare
Collections.synchronizedList()vs.List.of()(immutable list). -
What new methods does
java.nio.file.Pathprovide? -
How do you watch a directory for file events using
WatchService? -
How do you execute JavaScript with the Nashorn engine?
-
How would you implement a simple memoization helper using Java 8 features?
-
How do you profile and debug a long-running Stream pipeline?
-
Explain the role of
Supplier,Consumer,Function, andPredicatein thejava.util.functionpackage. -
What is
Stream.peek()and when is it useful (or dangerous)? -
How does
Collection.removeIf()differ fromStream.filter()? -
How do you use
Optionalto safely navigate nested properties (avoid NPEs)?
Advanced (30 Questions)
-
How do you implement a custom Spliterator for a domain-specific data structure?
-
Walk through building a complex Collector with
Collector.of(), includingUNORDEREDorCONCURRENTcharacteristics. -
What pitfalls arise from stateful intermediate operations in parallel Streams?
-
Describe how the ForkJoinPool underpins
parallelStream()execution. -
How would you tune parallel Stream performance for very large data sets?
-
How do you supply a custom Executor to a
CompletableFuture? -
How do you enforce timeouts in
CompletableFutureworkflows? -
Compare
handle(),exceptionally(), andwhenComplete()for error handling inCompletableFuture. -
How can you implement backpressure or flow control using Java 8 constructs?
-
How do you support cancellation in chained
CompletableFutures? -
Implement a Collector that dynamically buckets data based on a runtime criterion.
-
Simulate sliding-window aggregations (time-based) using Streams.
-
How do you use MethodHandle to invoke a private method reflectively?
-
What is
invokedynamic, and how did Java 8 improve dynamic language support? -
How would you implement a tail-recursive algorithm in Java 8 (without native tail calls)?
-
Design a mini-DSL using functional interfaces and default methods.
-
How do you leverage type annotations (
@Target(ElementType.TYPE_USE)) introduced in Java 8? -
How do repeatable annotations work, and how do you access them via reflection?
-
Create and use a custom annotation processor in Java 8.
-
Build bi-directional Java↔JavaScript interop logic using the Nashorn engine.
-
Convert a Stream<CompletableFuture> into
CompletableFuture<List<T>>. -
How do you correctly parallelize nested Stream pipelines?
-
Implement a lock-free, thread-safe data structure using
AtomicReferenceorAtomic*classes. -
Use StampedLock for optimistic read/write patterns.
-
Create a dynamic proxy via the LambdaMetafactory.
-
Optimize GC pressure when working with large Streams and avoid memory leaks.
-
Architect a reactive event-driven framework using core Java 8 features.
-
Migrate a legacy callback-based API to a
CompletableFuture-based design. -
Use
Optionaland Streams to build fluent guard clauses in your code. -
How do you write unit tests for complex Stream and
CompletableFuturepipelines using JUnit and Mockito?
Good luck with your Java 8 interview prep!

Comments
Post a Comment