In this example we design a model class with validation to use NotNull,Size,NotBlank and pattern. NotBlank means there should be pass some message. Size means we pass length of message.
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
public class EmployeeDetail {
@NotBlank(message = "empName should not be blank")
@Size(min = 4, max = 20, message = "empName length should be between 4 and 20")
@Pattern(regexp = "[a-zA-Z0-9]+$", message = "invalid empName no")
@NotNull
private String empName;
}