Understanding the Java main Method: Why It Is public static void and Takes String[] Args
This article explains the purpose and required signature of Java's main method, detailing why it must be public, static, return void, and accept a String[] argument, and describes how the JVM launches and invokes this entry point.
In Java, the main method is the entry point of any application; the JVM starts by loading a specified class and invoking its main method.
When writing the first "Hello World" or a Spring Boot web application, a main method with the signature public static void main(String[] args) is required.
In IntelliJ IDEA, typing psvm automatically generates this method.
The method signature is always public, static, returns void, and takes a single parameter of type String[] (or String... args ), with only the parameter name being changeable.
The public modifier is necessary because the JVM must be able to call the method from outside the class hierarchy.
The static modifier allows the JVM to invoke the method without creating an instance of the class, as the method is loaded during class initialization.
The return type is void because the JVM controls program termination; any exit code is handled by the runtime, making a return value unnecessary.
The parameter is a string array so that command‑line arguments, which are always strings, can be passed to the program, possibly multiple values.
According to the Java Language Specification, the JVM starts by loading the designated class, linking and initializing it, and then calling its main method with the supplied arguments.
In summary, the main method’s public static void signature with a String[] argument is designed to allow the JVM to invoke the program entry point directly, without needing an object instance, while providing a way to receive command‑line parameters.
Full-Stack Internet Architecture
Introducing full-stack Internet architecture technologies centered on Java
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.