Optional is used to avoid null checks and prevent NullPointerExceptions.
The `Optional` class in Java provides a way to represent optional values that may or may not be present. It helps eliminate null checks and reduce the risk of `NullPointerExceptions`. For example, `Optional userOpt = findUserById(id);` allows using `userOpt.ifPresent(user ->...)` to safely operate on the user if present.