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
Java Introduction
What is Java? JDK, JRE and JVM
Java Install and Setup
Your First Java Program: Hello World
Java Syntax
Java Comments
Java Cheat Sheet
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is the difference between Java and JavaScript?
What is Java?
What are the main features of Java?
What is the difference between JDK, JRE and JVM?
Why is Java platform independent?
What is bytecode in Java?
Why is the main method public static void in Java?