End of an era: Java’s main method is no longer the canonical “bad” syntax example

Brian Schlining
Sep 19, 2023

When was the last time you saw this comparison of why Java syntax is bad:

// HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
# hello_world.py
print("Hello World")

With the release of Java 21, you can now do this:

// HelloWorld.java. Run with `java --enable-preview --source 21 HelloWorld.java`
void main() {
System.out.println("Hello World");
}

BTW, the python example most folks show is almost always wrong. The correct form is actually:

# hello_world.py
def main():
print("Hello World")

if __name__ == "__main__":
main()

--

--

Brian Schlining

Polyglot coder. Deep-sea Researcher. Zazen aficionado. I think squids are pretty cool.