GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • java.evolved
  • ←
  • →

This view

  • Original page
  • New address

GeezerVison is showing javaevolved.dev — Compact source files | java.evolved

Home / Language / Compact source files
Language Beginner

Compact source files

  • 🐛 Report a code issue
  • 🌐 Report a translation issue
  • 💡 Suggest a new pattern

Write a complete program without class declaration or public static void main.

Tooling
Code Comparison
✕ Java 8
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println(
            "Hello, World!");
    }
}
✓ Java 25
void main() {
    IO.println("Hello, World!");
}
Share 𝕏
See a problem with this code? Let us know.
Why the modern way wins
🚀

Zero ceremony

No class, no public static void main, no String[] args.

🎓

Beginner-friendly

New programmers can write useful code from line 1.

📝

Script-like

Perfect for quick prototypes, scripts, and examples.

Old Approach
Main Class Ceremony
Modern Approach
void main()
Since JDK
25
Difficulty
Beginner
JDK Support
Compact source files
Available

Finalized in JDK 25 LTS (JEP 512, Sept 2025).

How it works

Compact source files remove the ceremony of class declarations and the main method signature for simple programs. Combined with implicit import of java.io.IO, even println is available directly.

Related Documentation
Simple Source Files and Instance Main Methods (JEP 495) ↗
Proof
View proof source ↗
Related patterns
Language Beginner

Type inference with var

Java 8
Map<String, List<Integer>> map =
    new HashMap<String, List<Integer>>();
for (Map.Entry<String, List<Integer>> e
    : map.entrySet()) {
    // verbose type noise
}
Java 10+
var map = new HashMap<String, List<Integer>>();
for (var entry : map.entrySet()) {
    // clean and readable
}
Hover to see modern ➜
JDK 10+ →
Language Beginner

Text blocks for multiline strings

Java 8
String json = "{\n" +
    "  \"name\": \"Duke\",\n" +
    "  \"age\": 30\n" +
    "}";
Java 15+
String json = """
    {
      "name": "Duke",
      "age": 30
    }""";
Hover to see modern ➜
JDK 15+ →
Language Beginner

Switch expressions

Java 8
String msg;
switch (day) {
    case MONDAY:
        msg = "Start";
        break;
    case FRIDAY:
        msg = "End";
        break;
    default:
        msg = "Mid";
}
Java 14+
String msg = switch (day) {
    case MONDAY  -> "Start";
    case FRIDAY  -> "End";
    default      -> "Mid";
};
Hover to see modern ➜
JDK 14+ →
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.