The Hello Single
Java clears its throat, names a class, and finds a semicolon. Groovy just says hello.
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Jon!");
}
}
A five-track syntax remix
It’s 2004. Java is wearing a sensible tie. A strange new language has entered the club, loosened the boilerplate, and put closures on the turntable.
Tonight’s challenge
For each stiff Java snippet, choose the Groovy remix that keeps the intent while making the code sing. Each right answer restores another layer of colour to the club.
Java clears its throat, names a class, and finds a semicolon. Groovy just says hello.
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Jon!");
}
}
Turn a loop and an accumulator into one expressive move.
List<Integer> doubled = new ArrayList<>();
for (Integer n : numbers) {
doubled.add(n * 2);
}
Drop the concatenation clutter and let the value step directly into the lyric.
String name = "Nathan";
System.out.println("Welcome, " + name + "!");
Ask for a nested value without building a small defensive fortress.
String city = null;
if (person != null && person.getAddress() != null) {
city = person.getAddress().getCity();
}
Build a tiny record without constructors, setters, or ceremony.
Map<String, Object> book = new HashMap<>();
book.put("title", "Programming Pearls");
book.put("pages", 256);
Five for five • encore unlocked
You turned 23 lines of ceremony into five little declarations. That was Groovy’s delicious original promise: familiar Java-world power with more room for human expression.