A tour through Java versions (runs on Java 17)
Each comment names the version a feature arrived in. The newest feature here is from Java 16, so the browser's Java 17 runs it.
A new Java version comes out every March and September, and every two years one of them is a Long-Term Support (LTS) release that companies stay on for years: Java 8, 11, 17, 21 and 25. This course tags each feature with the version that introduced it (such as Java 16), and the in-browser Run button uses Java 17.
Change the code and press Run (Ctrl+Enter). Try to predict the output first, then break it on purpose and read the error. Your edits are saved and match the lesson page.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Rewrite this Java 14 switch expression as an old-style if/else chain that works on Java 8: String size = switch (n) { case 0 -> "none"; case 1 -> "one"; default -> "many"; }; with n = 1, and print the result.
Write a program that uses "ab".repeat(3) (Java 11) and " hi ".strip() (Java 11), and prints both results inside square brackets.
Write a program that prints whether the running Java has virtual threads (Java 21) using Runtime.version().feature(). What does it print in the browser?
Explain it without notes
What does LTS mean, and why do most companies run an LTS version?
List the five LTS versions and one headline feature for each.
What is a preview feature, and how do you use one?
What does javac --release 17 do, and why is it better than just compiling with the newest JDK?
What does a Java 21 badge on a code example in this course mean for you?
Expected output
Total age: 10
Milo is 3
Luna is 7
============
We have many pets
Milo is young
Pet[name=Milo, age=3]