The classic version of a small program
From Java 25 a complete program can be just void main() { IO.println("Hello"); }: no class declaration, no public static, no String[] args. The compiler wraps the file in a hidden class, the launcher creates an object and calls main on it, and common java.base packages are imported automatically.
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.
Write the Java 25 compact-file version of a program that prints the first 10 Fibonacci numbers on one line using a helper method fib(int n). Then write and run the Java 17 version.
A class has both public static void main(String[] args) printing "static" and void main() printing "instance". What does java Main print on Java 17, and on Java 25? Write it and run it on Java 17.
Rewrite this Java 17 class as an explicit class with an instance main method that runs on Java 25 (keep the class declaration): a class Counter with a field int n, a method inc(), and a main that calls inc() three times and prints n.
Explain it without notes
What is a compact source file, and what does the compiler do with it?
What is an instance main method and how does the launcher run it?
In what order does the Java 25 launcher choose a main method?
Why was this feature added, and does it change existing programs?
Expected output
1. buy milk
2. learn records
3. call Asha
3 tasks