Why: Setting required = false tells Spring that the parameter is not mandatory. required = true is the default and causes an error when the value is missing.
6. A String parameter uses @RequestParam(required = false). What value does the method get when the request does not send it?
Why: With required = false, a missing parameter is passed as null. You need to check for null yourself.
7. A parameter is declared as Optional and the request does not send it. What does the method receive?
Why: Spring passes an empty Optional when the value is missing. The method is still called and no error happens.
8. When a parameter is declared as Optional, do you also need to set required = false to avoid a 400 error?
Why:Optional is an alternative to required = false. You do not need to use both.
9. Which parameter declaration correctly uses Optional for a request parameter?
public String handle(______ ) { ... }
Why: The parameter type is Optional<String>. The generic type inside is the type of the value you expect.
10. Which Optional method returns the value if present, or a given default value if it is empty?
String dept = deptName.______("default dept");
Why:Optional.orElse(value) returns the contained value, or the given default value if the Optional is empty.
11. Besides @RequestParam, which annotations can be used with java.util.Optional?
Why: Spring supports Optional with @RequestParam, @RequestHeader and @MatrixVariable.
12. Why does Spring support java.util.Optional in handler methods?
Why: Spring always tries to align the framework with standard JSE/JEE APIs. Supporting Optional is part of that.
13. In which package is the Optional class used for handler parameters found?
Why: The class is java.util.Optional. It is part of the standard JDK, not Spring.