Java 8 Interview
Java 8 Interview
• What is Java 8?
• Tell a few functional interfaces which were already available before Java 8.
• How to call a default interface method in a class that implements this interface?
Stream API
• What are the selection operations available in the Java 8 Stream API?
• What are reducing operations? Name some of the reducing operations available in the Java 8
streams.
• What is the role of reduce in Streams?
Optional Class
• How does the Optional class help in handling null values in Java 8?
• What are some best practices for using Optional effectively? When should Optional be used,
and when should it be avoided?
• What are the key advantages of using the new Date and Time API over the older Date and
Calendar classes?
• What is CompletableFuture?
• How do you ensure thread safety when working with Java 8 features such as streams and
CompletableFuture?
• How do you use parallel streams in Java 8 to improve performance for large datasets? What
are the risks associated with parallel streams?
• What is a Spliterator?
• What is the difference between map() and peek() in the Stream API?
• How would you process a list of transactions to filter and summarize data using Java
Streams?
• How would you refactor a piece of code to use lambda expressions and functional
interfaces?
• How would you use the new Date and Time API in Java 8 to calculate the difference between
two dates?
• How many ways are there to print keys & values of a Map?
• How to remove all duplicates from an array of integers in Java using Java 8?
• How to count the number of occurrences of a given word in a list of strings using Java 8?
• Write a Java program using Stream to create a map from a list of strings where the key is the
string and the value is its length?
• How to filter and collect a list of strings that start with a specific letter using Java 8 Stream?
• How to find the maximum value in a list of integers using Stream & Method Reference?
• Join a list of strings with '[' as prefix, ']' as suffix, and ',' as delimiter.
• Print the numbers from a given list of integers that are multiples of 5.
• Merge two unsorted arrays into a single sorted array using Java 8 streams.
• Merge two unsorted arrays into a single sorted array without duplicates.
• Get the three maximum and three minimum numbers from a given list of integers.
• Java 8 introduced several new methods like forEach(), removeIf(), and replaceAll() in the
Collection interface. Can you give examples of how you used them?