Java 25 Changes main(): No More Mandatory public static
Java 25 simplifies main(): no more mandatory public static. Learn which access modifiers are allowed, the new launch rules, and code examples.

For almost 30 years, every Java developer has typed the same line without thinking: public static void main(String[] args). With Java 25 (LTS), that ritual is finally optional. The change is a final feature (JEP 512), not a preview.
TL;DR:
main()no longer has to bepublicorstatic. It just must not beprivate. TheString[] argsparameter is optional too.
What Changed?
Before Java 25, the launcher demanded an exact method signature. Now it is flexible.
| Rule | Old Java | Java 25 |
|---|---|---|
| Access modifier | Must be public | public, protected or package-private (only private is rejected) |
static | Mandatory | Optional (instance main allowed) |
String[] args | Mandatory | Optional |
Before vs After
The old way:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
The Java 25 way:
class Hello {
void main() {
IO.println("Hello, Java 25!");
}
}
No public, no static, no args. Run it with java Hello.java.
How Does the Launcher Pick main()?
If a class has several candidates, Java 25 checks them in this order:
static void main(String[] args)static void main()void main(String[] args)(instance)void main()(instance)
For an instance main, the class needs a non-private constructor with no arguments, because Java creates the object for you.
Which Access Modifiers Work?
class A { void main() { } } // OK (package-private)
class B { protected void main() { } } // OK
class C { public void main() { } } // OK
class D { private void main() { } } // NOT allowed
Bonus: Compact Source Files
Java 25 also lets you write a file containing just a method, with no class wrapper:
void main() {
String name = "Prabhat";
IO.println("Welcome, " + name);
}
The IO class (java.lang.IO) gives you simple println and readln methods instead of System.out.println.
Why Does This Matter?
- Beginners can learn Java without facing
public static voidon day one. - Scripts and quick tests become much shorter.
- Teaching and interviews get cleaner code.
Should You Change Production Code?
Not necessarily. Real applications (Spring Boot, other frameworks) still use the classic main, and it keeps working. This feature mainly helps with learning, prototypes and small tools.
FAQ
Is the old public static void main(String[] args) deprecated?
No. It works exactly as before and has the highest priority.
Can main be private?
No. private is the one access level the launcher rejects.
Is Java 25 an LTS release? Yes. Java 25 is a Long-Term Support release.
Final Thoughts
Java 25 makes the language friendlier without breaking old code. Try it today: install JDK 25 and run java Hello.java.
What do you think about this change? Share your take in the comments.
Stay ahead of artificial intelligence & systems code.
One email a week with the biggest AI and dev news. No spam. Unsubscribe anytime.