Which statement correctly describes the difference between @NotNull and @NotEmpty annotations in Spring Boot validation?
Think about whether empty strings or empty collections are allowed.
@NotNull only checks that the value is not null but allows empty strings or empty collections. @NotEmpty checks that the value is not null and also not empty (length > 0 for strings, size > 0 for collections).
Given a Spring Boot model with a string field annotated with @NotBlank, what input value will cause validation to fail?
public class User { @NotBlank private String username; // getters and setters }
Remember what @NotBlank checks for in strings.
@NotBlank fails validation if the string is null, empty, or contains only whitespace characters. A string with spaces only is considered blank.
Which code snippet correctly applies @NotEmpty to a list field in a Spring Boot model to ensure it is not null and not empty?
Consider which data types @NotEmpty supports.
@NotEmpty supports strings, collections, maps, and arrays. Option A uses a List which is a collection, so it is valid. Option A uses a string which is valid but the question asks for a list. Option A uses a Map which is valid but the question asks for a list. Option A uses an array, not a list.
Consider this Spring Boot model:
public class Product {
@NotBlank
private Integer quantity;
}Why will validation fail or not work as expected?
Check the supported types for @NotBlank.
@NotBlank is designed to validate strings (CharSequence). It does not apply to numeric types like Integer. For numeric fields, @NotNull or other numeric validations should be used.
Given this Spring Boot model:
public class UserProfile {
@NotNull
private String id;
@NotBlank
private String name;
@NotEmpty
private List roles;
// getters and setters
} Which input will pass all validations?
Check each annotation's requirement for each field.
@NotNull requires id not to be null.@NotBlank requires name not to be null, empty, or whitespace.@NotEmpty requires roles not to be null or empty.
Option C meets all these conditions.