Java 8 Interview Questions Answers
Java 8 Interview Questions Answers
3. Method References
can become:
1 Object::toString();
4. Optional
4 assertEquals(1, min1);
5
7 .min()
.orElse(0);
8
assertEquals(0, min2);
9
5. Functional Interfaces
Q1. Describe some of the functional interfaces in
the standard library.
There are a lot of functional interfaces in
the java.util.function package, the more common ones include but
not limited to:
3 System.out.println("Hello World!");
4 }
5 });
6. Default Method
4 System.out.println("peep!");
5 }
}
6
4
5 default void count() {
}
7
}
8
Yes. The code will compile because it follows the functional interface
specification of defining only a single abstract method. The second
method, count, is a default method that does not increase the
abstract method count.
7. Lambda Expressions
8. Nashorn Javascript
Q1. What is Nashorn in Java8?
Nashorn is the new Javascript processing engine for the Java
platform that shipped with Java 8. Until JDK 7, the Java platform used
Mozilla Rhino for the same purpose. as a Javascript processing
engine.
Nashorn provides better compliance with the ECMA normalized
JavaScript specification and better runtime performance than its
predecessor.
9. Streams
.map(i -> i * 3)
3
.sum();
4
3
3 doubling 1
4 doubling 2
doubling 3
5
As you can see, the intermediate operations are only triggered when
a terminal operation exists.
5
.flatMap(Collection::stream)
7
.collect(Collectors.toList());
8