Java8 revolutionised Java programming with the introduction of functional programming.
Here is a little quiz (you ‘ll find the answers below):
1 . What is the name of the abstract method of the Consumer interface?
2 . Which method can you call on Optional to perform an action when the Optional contains a value?
3 . What is false? A stream …
A. needs to have intermediate operations
B. needs to have a terminal operation
C. is lazily initialised
D. can have multiple intermediate operations
4 . Which one does not compile?
A. Stream<Integer> empty = Stream.empty()
B. Stream<Integer> stream = Stream.of(1)
C. Stream<Integer> stream = Stream.of(1,2,3)
D. They all compile
5 . Stream.reduce(T identity, BinaryOperator<T> accumulator); When no identity is specified…
A. The code does not compile
B. A runtime expression may be thrown
C. Optional is returned
6 . limit() and skip() methods make a Stream …
7 . Which method is useful for debugging by allowing an operation without changing the stream.
8 . Which stream does not contain 5 elements?
B. IntStream.iterate(1 , n -> ++n).skip(5).limit(5)
C. IntStream.range(1, 5)
D. IntStream.rangeClosed(1, 5)
9 . Stream<Integer> s =Arrays.asList(1, 2).stream(); s.add(4); System.out.println(stream.count());
A. prints 4
B. prints 3
C. prints 2
10 . IntStream.rangeClosed(0, 20).boxed() .collect(Collectors.toMap(n -> n, n -> n*n)));
A. Does not compile
B. returns a map with the squared keys as values
C. Throws a runtime exception
11 . True or False? sum() is a terminal operation on the Stream class.
12 . We can sort a stream with which method?
13 . Performing .sum() on an empty IntStream returns
A. a RunTimeException
B. an int
C. an OptionalInt
14 . Which interface does not exist?
15 . Which Supplier does not exist?
1 : B
2 : C
3 : B
4 : D
5 : C
6 : A
7 : B
8 : C
9 : B
10 : B
11 : B
12 : B
13 : B
14 : C
15 : D
Check out my Kahoot to check where your knowledge is at!?