Why is the main method public static void in Java?

The JVM starts a program by calling public static void main(String[] args).

  • public: the JVM is outside your class, so the method must be visible.
  • static: the JVM calls it before any object exists.
  • void: it does not return a value to the JVM.
  • String[] args: the command line arguments.

Since Java 25 you can write a short form for small programs, with no class and no public static:

void main() {
    IO.println("Hello from a compact source file");
}
Output

Hello from a compact source file

See Your First Java Program.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.