Exploring Java 8 Features: Streams, Lambdas, and More
Test your knowledge of Java 8's key features including streams, lambdas, and functional interfaces.
Questions in this quiz
12 questions on Exploring Java 8 Features: Streams, Lambdas, and More. Work through them here, then start the quiz to answer them and see your score.
1.What is the primary purpose of the `Stream` API introduced in Java 8?
- ATo replace the existing I/O streams
- BTo enable functional-style operations on collections
- CTo enhance file handling capabilities
- DTo provide a new data structure for collections
2.Which of the following is a valid lambda expression in Java 8?
- Aa, b -> a + b
- B(a, b) => a + b
- Cint a, int b -> a + b
- D(int a, int b) -> a + b
3.What is the role of the `Optional` class in Java 8?
- ATo enhance exception handling
- BTo provide a container that may or may not contain a non-null value
- CTo replace all null checks
- DTo handle null pointer exceptions
4.Which functional interface in Java 8 is used to represent a function that accepts one argument and produces a result?
- APredicate
- BFunction
- CConsumer
- DSupplier
5.In Java 8, which method reference type is used to refer to a constructor?
- AClass::construct
- BClass::create
- CClass::init
- DClass::new
6.What is the purpose of the `default` keyword in interfaces introduced in Java 8?
- ATo specify a default visibility
- BTo declare a constant
- CTo provide a default implementation for methods
- DTo define a default constructor
7.How can you convert a `List<String>` to a `Stream<String>` in Java 8?
- AStream.from(list)
- Blist.toStream()
- CStream.of(list)
- Dlist.stream()
8.Which of the following is NOT a characteristic of streams in Java 8?
- AStreams are lazy
- BStreams are immutable
- CStreams can be reused
- DStreams can be parallelized
9.What does the `filter` method do in a Java 8 stream?
- ASorts the elements
- BAggregates the elements
- CRemoves elements that don't match a predicate
- DTransforms each element
10.Which Java 8 feature allows you to execute code on multiple threads more easily?
- AThread Pools
- BParallel Streams
- CFork/Join Framework
- DSynchronized Blocks
11.What is the purpose of the `Collectors` utility class in Java 8?
- ATo collect metadata about classes
- BTo collect garbage
- CTo collect elements from a stream into a collection
- DTo collect input from users
12.Which method in the `Stream` API is used to transform each element in a stream?
- Afilter()
- Bmap()
- Ccollect()
- Dreduce()