2. What is Optional in Java 8 ?

Java 8 added a new class java.util.Optional that provides a way to handle situations where a value may or may not be present. Optional is a container object which may or may not contain a not null value.

Optional class forces us to deal with absense of a value. This helps prevent Null pointer exceptions at runtime.