Complete the code to declare a constant for the maximum number of users.
public class Config { public static final int MAX_USERS = [1]; }
Constants in Java are declared using public static final and assigned a fixed value like 100.
Complete the method to override the toString method properly.
public class Person { private String name; @Override public String toString() { return [1]; } }
toString() on a String variable unnecessarily.Overriding toString() should return a meaningful string, like "Person: " plus the name.
Fix the error in the method to properly close the resource using try-with-resources.
public void readFile(String path) {
try (BufferedReader reader = new BufferedReader(new FileReader([1]))) {
System.out.println(reader.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}The variable path is passed as the filename to FileReader. Using the string "path" would look for a file literally named 'path'.
Fill both blanks to create a for-each loop that prints each element in the list.
List<String> items = List.of("apple", "banana", "cherry"); for ([1] : [2]) { System.out.println(item); }
A for-each loop uses the syntax: for (Type variable : collection). Here, String item and items are correct.
Fill all three blanks to create a map comprehension that filters and transforms entries.
Map<String, Integer> result = data.entrySet().stream()
.filter(e -> e.getValue() [1] [2])
.collect(Collectors.toMap(
e -> e.getKey().toUpperCase(),
e -> e.getValue() [3] 2
));This code filters entries with values greater than 10, then collects them into a map with uppercase keys and values multiplied by 2.