Bird
0
0

Given the following Spring Boot repository method call:

medium📝 state output Q13 of 15
Spring Boot - Docker and Deployment
Given the following Spring Boot repository method call:
Optional user = userRepository.findById(5L);

What will user.isPresent() return if no user with ID 5 exists in the database?
Atrue
BThrows an exception
Cnull
Dfalse
Step-by-Step Solution
Solution:
  1. Step 1: Understand findById return type

    findById returns an Optional which is empty if no matching record is found.
  2. Step 2: Check isPresent behavior

    isPresent() returns false when Optional is empty, meaning no user found.
  3. Final Answer:

    false -> Option D
  4. Quick Check:

    Optional empty means isPresent() = false [OK]
Quick Trick: Optional.isPresent() false means no data found [OK]
Common Mistakes:
  • Assuming isPresent() returns true always
  • Expecting null instead of Optional
  • Thinking it throws exception if not found

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes