Middle
What innovations appeared in Java 8 and JDK 8?
sobes.tech AI
Answer from AI
- Lambda Expressions
- Stream API
- Default Methods
- Optional Class
- Nashorn JavaScript Engine
- Date and Time API (JSR 310)
- New methods in Collections interface (e.g.,
forEach,removeIf) - Concurrent Accumulators (e.g.,
LongAdder,DoubleAdder) - Parallel Array Sorting
// Example Lambda Expression
Runnable r = () -> System.out.println("Hello from Lambda!");
// Example Stream API
List<String> list = Arrays.asList("a", "b", "c");
list.stream().filter(s -> s.startsWith("a")).forEach(System.out::println);
// Example Default Method
interface MyInterface {
void abstractMethod();
default void defaultMethod() {
System.out.println("Default implementation");
}
}
// Example Optional
Optional<String> optional = Optional.ofNullable("present");
optional.ifPresent(System.out::println);