0
0
Spring Bootframework~20 mins

@Min, @Max for numeric constraints in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Spring Boot Validation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when a value violates @Min constraint?
Consider a Spring Boot REST controller receiving a JSON with a field annotated with @Min(5). What happens if the client sends a value of 3 for that field?
Spring Boot
@RestController
public class SampleController {
  @PostMapping("/test")
  public String test(@Valid @RequestBody InputData data) {
    return "Value accepted";
  }
}

public class InputData {
  @Min(5)
  private int number;

  // getters and setters
}
AThe value is automatically adjusted to 5 before processing.
BThe request succeeds and the controller returns "Value accepted".
CThe server throws a NullPointerException.
DThe request is rejected with a 400 Bad Request and a validation error message.
Attempts:
2 left
💡 Hint
Think about how Spring Boot handles validation annotations with @Valid.
📝 Syntax
intermediate
1:30remaining
Which code snippet correctly applies @Max to a field?
Select the code snippet that correctly uses @Max to restrict a numeric field to a maximum value of 100.
A
@Max(limit=100)
private int score;
B
@Max(100)
private int score;
C
@Max(max=100)
private int score;
D
@Max(value=100)
private int score;
Attempts:
2 left
💡 Hint
Check the official annotation parameter name for @Max.
state_output
advanced
2:00remaining
What is the validation result for a field annotated with both @Min and @Max?
Given a field annotated with @Min(10) and @Max(20), what happens if the input value is 25?
Spring Boot
public class Data {
  @Min(10)
  @Max(20)
  private int value;

  // getters and setters
}
AValidation fails with a message about exceeding the maximum value.
BValidation fails with a message about being below the minimum value.
CValidation passes because only one constraint is checked at a time.
DValidation fails with messages about both minimum and maximum constraints.
Attempts:
2 left
💡 Hint
Consider which constraint is violated by the input value.
🔧 Debug
advanced
2:30remaining
Why does this @Min annotation not work as expected?
Identify the issue in this code snippet where @Min(1) is applied but negative values are still accepted.
Spring Boot
public class Product {
  @Min(1)
  private Integer quantity;

  // getters and setters
}
AThe @Min annotation only works on primitive types, not wrapper classes.
BThe field is an Integer object, so @Min does not validate it properly.
CThe validation is not triggered because @Valid is missing on the containing object.
DThe @Min annotation requires a message attribute to work.
Attempts:
2 left
💡 Hint
Think about how validation is triggered in Spring Boot controllers or services.
🧠 Conceptual
expert
3:00remaining
How does Spring Boot handle @Min and @Max on floating-point numbers?
If a field is a double and annotated with @Min(1) and @Max(10), which statement is true about validation behavior?
Spring Boot
public class Measurement {
  @Min(1)
  @Max(10)
  private double value;

  // getters and setters
}
A@Min and @Max treat the double as a long, so fractional parts are ignored during validation.
B@Min and @Max validate the exact double value including decimals.
CValidation fails because @Min and @Max do not support floating-point types.
D@Min and @Max only work if the double is wrapped in Double, not primitive double.
Attempts:
2 left
💡 Hint
Consider how Bean Validation API defines @Min and @Max behavior for floating types.