0
0
Spring Bootframework~10 mins

@NotNull, @NotBlank, @NotEmpty in Spring Boot - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to ensure the 'name' field cannot be null.

Spring Boot
public class User {
    @[1]
    private String name;
}
Drag options to blanks, or click blank then click option'
ANotEmpty
BNotBlank
CNotNull
DSize
Attempts:
3 left
💡 Hint
Common Mistakes
Using @NotBlank instead of @NotNull when only null check is needed.
Confusing @NotEmpty with @NotNull.
2fill in blank
medium

Complete the code to ensure the 'username' field is not null and not empty (no blank spaces).

Spring Boot
public class Account {
    @[1]
    private String username;
}
Drag options to blanks, or click blank then click option'
ANotEmpty
BNotNull
CSize(min=1)
DNotBlank
Attempts:
3 left
💡 Hint
Common Mistakes
Using @NotEmpty which allows strings with only spaces.
Using @NotNull which allows empty strings.
3fill in blank
hard

Fix the error in the code to ensure the 'tags' list is not null and contains at least one element.

Spring Boot
public class BlogPost {
    @[1]
    private List<String> tags;
}
Drag options to blanks, or click blank then click option'
ANotEmpty
BNotBlank
CNotNull
DSize(min=1)
Attempts:
3 left
💡 Hint
Common Mistakes
Using @NotBlank on a collection causes errors.
Using @NotNull allows empty collections.
4fill in blank
hard

Fill both blanks to validate 'email' so it is not null and not blank.

Spring Boot
public class Contact {
    @[1]
    @[2]
    private String email;
}
Drag options to blanks, or click blank then click option'
ANotNull
BNotBlank
CNotEmpty
DEmail
Attempts:
3 left
💡 Hint
Common Mistakes
Using only @NotNull allows blank strings.
Using only @NotEmpty does not check for blank spaces.
5fill in blank
hard

Fill all three blanks to create a map of word lengths for words longer than 3 characters.

Spring Boot
Map<String, Integer> wordLengths = words.stream()
    .filter(word -> word.length() [1] 3)
    .collect(Collectors.toMap(
        word -> word.[2](),
        word -> word.[3]()
    ));
Drag options to blanks, or click blank then click option'
A>
BtoUpperCase
Clength
DstartsWith
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > in filter.
Using startsWith instead of toUpperCase for keys.
Using toUpperCase instead of length for values.