Introduction to Java 8 Features
A beginner's quiz on Java 8 features including lambdas, streams, and more.
Questions in this quiz
15 questions on Introduction to Java 8 Features. Work through them here, then start the quiz to answer them and see your score.
1.What is a lambda expression in Java 8?
- AA replacement for classes
- BA way to define anonymous functions
- CA method to handle exceptions
- DA new type of loop
2.Which of the following is a valid lambda expression?
- A(int a, int b) -> a + b
- Bfunction(a, b) => a + b
- Cdef lambda(a, b): a + b
- Dlambda (a, b) { return a + b; }
3.What is the purpose of the 'Optional' class introduced in Java 8?
- ATo perform mathematical operations
- BTo replace all arrays
- CTo handle null pointer exceptions
- DTo improve file handling
4.What does the 'Stream' API in Java 8 allow you to do?
- AManage database connections
- BCreate graphical interfaces
- CProcess sequences of elements
- DHandle network protocols
5.Which method is used to filter elements in a Stream?
- Acollect()
- Bfilter()
- Creduce()
- Dmap()
6.What is the default method in interfaces introduced in Java 8?
- AA method without a return type
- BA method that must be overridden
- CA method that throws exceptions by default
- DA method with a body in an interface
7.Which of the following is a characteristic of a functional interface?
- AIt cannot have any methods
- BIt has multiple abstract methods
- CIt has exactly one abstract method
- DIt must extend another interface
8.What does the 'map()' method do in a Stream?
- ATransforms each element
- BCombines elements
- CSorts elements
- DFilters elements
9.How are method references represented in Java 8?
- AmethodName::ClassName
- BClassName->methodName
- CClassName::methodName
- DmethodName->ClassName
10.Which of the following is a benefit of using streams in Java 8?
- AFaster compilation times
- BReduced memory usage
- CImproved readability and efficiency
- DSimplified exception handling
11.What does the 'forEach()' method do in a Stream?
- AFilters elements
- BSorts elements
- CPerforms an action for each element
- DCombines elements
12.What is the purpose of the 'Collectors' class in Java 8?
- ATo perform mathematical calculations
- BTo handle exceptions
- CTo manage file operations
- DTo accumulate elements of a stream into collections
13.Which of the following is a valid use of the 'reduce()' method?
- ATo filter elements
- BTo combine elements of a stream
- CTo sort elements
- DTo transform elements
14.What is a key characteristic of the 'Optional' class?
- AIt is used for file operations
- BIt can contain a single value or be empty
- CIt replaces arrays
- DIt always contains a value
15.Which feature allows interfaces to have methods with implementations in Java 8?
- AStatic methods
- BDefault methods
- CFinal methods
- DAbstract methods