Java Refresh Test (Java 9 to 25)
Coming back to a city you lived in years ago is a strange feeling. The streets are where you left them, but there is a new metro line, your old shortcut is now one-way, and everyone pays with their phone. Java after Java 8 feels the same. The language you knew still works, but there are records, var, text blocks, switch expressions, pattern matching, virtual threads and a new release every six months. This test is for the Refresh track. Every question is about a feature added in Java 9 or later.
How the Test Works
- What's in it: 20 multiple-choice questions, then 3 output puzzles where you work out what a short program prints.
- Time: 30 minutes, without notes, an IDE or JShell.
- Pass mark: 16 out of 23. The quiz marks the 20 questions for you. Mark the puzzles yourself, one point each, and add them to your quiz score.
- What it covers: language, library and JVM features from Java 9 to Java 25. Start with Java 9 to 11 Features if most of these are new to you.
Part 1: 20 Questions
Part 2: Output Puzzles
Work out what each program prints, on paper, before you open the solution. The solution shows the full program, its real output and a Try it button. Give yourself one point for each puzzle you get exactly right.
Puzzle 1: First, Last and Reversed
What is printed? (Java 21 or later)
var list = new ArrayList<>(List.of(3, 1, 2));
list.addFirst(0);
System.out.println(list.reversed());Show solution
import java.util.ArrayList;
import java.util.List;
public class SequencedPuzzle {
public static void main(String[] args) {
var list = new ArrayList<>(List.of(3, 1, 2));
list.addFirst(0);
System.out.println(list.reversed());
}
}[2, 1, 3, 0]Why this output?
addFirst(0) makes the list [0, 3, 1, 2]. reversed() returns a reversed view of it, without sorting anything. Revise: Sequenced Collections in Java.
Puzzle 2: A Guarded Case
What is printed?
Object o = 42;
String r = switch (o) {
case Integer i when i > 40 -> "big int " + i;
case Integer i -> "int " + i;
case String s -> "string " + s;
default -> "other";
};
System.out.println(r);Show solution
public class GuardPuzzle {
public static void main(String[] args) {
Object o = 42;
String r = switch (o) {
case Integer i when i > 40 -> "big int " + i;
case Integer i -> "int " + i;
case String s -> "string " + s;
default -> "other";
};
System.out.println(r);
}
}big int 42Why this output?
The cases are tried from top to bottom, and the first match wins. 42 is an Integer and the guard i > 40 is true, so the first case matches. Revise: Guards in Switch (When Clause).
Puzzle 3: Counting Lines in a Text Block
What is printed?
String json = """
{
"name": "Java"
}
""";
System.out.println(json.lines().count());Show solution
public class TextBlockPuzzle {
public static void main(String[] args) {
String json = """
{
"name": "Java"
}
""";
System.out.println(json.lines().count());
}
}3Why this output?
The line with the opening """ isn't part of the text, and the common indentation is removed. That leaves three lines: {, "name": "Java" and }. The closing """ on its own line adds a final line break, but not a fourth line. Revise: Text Blocks in Java.
What Your Score Means
| Score (out of 23) | What it means | What to do next |
|---|---|---|
| 20 to 23 | You are up to date with modern Java | Try the Java Deep Dive Test, or move on to Core Java Interview Questions |
| 16 to 19 | A pass, with a few gaps | Read the lessons linked from the questions you missed |
| Under 16 | Not yet | Work through Java 9 to 11 Features and the lessons that follow it, then take the test again |
Was this tutorial helpful?