Performance: @Min, @Max for numeric constraints
These annotations affect server-side validation speed and response time but do not impact client-side rendering or page load.
Jump into concepts and practice - no test required
import jakarta.validation.constraints.Min; import jakarta.validation.constraints.Max; public class UserInput { @Min(18) @Max(65) private int age; }
public class UserInput { private int age; // No validation annotations }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No @Min/@Max validation | 0 | 0 | 0 | [OK] No impact on frontend but backend slower |
| With @Min/@Max validation | 0 | 0 | 0 | [OK] No frontend impact, better backend validation |
What is the main purpose of using @Min and @Max annotations in Spring Boot?
Which of the following is the correct way to apply @Min and @Max annotations on an integer field age to restrict it between 18 and 65?
public class Person {
// Which is correct?
private int age;
}Given the following Spring Boot entity snippet, what will happen if score is set to 105?
public class GameScore {
@Min(0)
@Max(100)
private int score;
// getters and setters
}Identify the error in this code snippet that uses @Min and @Max:
public class Product {
@Min(1)
@Max(100)
private String quantity;
// getters and setters
}You want to create a Spring Boot model field rating that only accepts values from 1 to 5 inclusive. Which of the following code snippets correctly enforces this using @Min and @Max?