Basic Java

Test Your Knowledge

Answer all 10 questions, then submit to see your score.

1. What does the BufferedReader.readLine() method return when there's nothing left to read?

2. What will be the output of the following code?

enum Day { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY }
System.out.println(Day.MONDAY.ordinal());

3. What happens if you call Files.createDirectories() on a path where the directory already exists?

4. Which class is recommended for building strings piece by piece in a loop?

5. What will the resulting file contain after this code runs?

try (BufferedWriter w = new BufferedWriter(new FileWriter(path.toFile()))) {
    w.write("Line1");
    w.write("Line2");
}

6. What is the primary characteristic of a String in Java?

7. What does it mean that Java arrays are covariant?

8. What happens when Files.copy(source, dest) is called and the destination file already exists?

9. Identify the best practices when working with wrapper classes.

10. Which methods are used for replacing parts of a string?