In a traditional Java application, public static void main(String[] args) is the familiar method the Java launcher uses to start the program. public makes it accessible to the launcher, static lets the launcher call it without creating an object first, void means it returns no value, and String[] args receives command-line arguments.
Why a Java program has a main method
A conventional class-based Java application needs a starting point. When you launch the application, Java looks for a candidate main method in the initial class or interface and invokes it. The method can then call other methods to do the program’s work.
As an Amazon Associate I earn from qualifying purchases.
The familiar declaration is the standard beginner example. The Java SE 26 Language Specification describes the current startup rules, which include more candidate forms than this traditional signature.
What each part of public static void main(String[] args) means
| Part | Meaning |
|---|---|
public |
Makes the method accessible to the launcher in the traditional declaration. |
static |
Lets the launcher invoke the method on the class without first creating an instance of it. |
void |
Declares that the method returns no value to the launcher. |
main |
The conventional entry-point method name. |
String[] args |
An array of strings that receives command-line arguments. args is a conventional parameter name; the identifier can be changed. |
In the traditional form, public and static may appear in either order. The commonly taught spelling puts public first.
How command-line arguments reach the program
Arguments written after the class name in a launch command are passed to the method as strings in its args array. For example, in java MyApp arg1 arg2, the application receives arg1 and arg2 as array elements. A program can inspect those values to adjust its behavior; the simplest Hello World example usually ignores them.
What the Hello World print statement does
System.out.println("Hello World!"); calls println on Java’s standard-output stream, displaying the text followed by a line break. The method is inside main, so it runs when the launcher invokes that entry point.
Rank #2
Compile and run the traditional example
Save this class in a file named Test.java:
class Test {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
- Compile it from a terminal in the directory containing the file:
javac Test.java. - Run the compiled class:
java Test. - To pass arguments, add them after the class name, as in
java Test Hello, world.. The values afterTestare passed to the program as strings.
Is this exact signature required in every Java release?
No. The declaration above remains the conventional class-based beginner form, but entry-point rules are version-specific. The Java SE 26 Language Specification permits a broader set of candidate main methods, including methods without a parameter and instance methods. Java SE 25 significantly expanded the accepted forms; earlier releases followed different rules.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsJava SE 21 documented unnamed classes and instance main methods as a preview feature for that release. That is historical, version-specific context, not a description of the current rules. When using a newer simplified source form or explaining an alternative entry point, identify the Java release your example targets.
Quick Recap
Best Value
Rank #4
Official references
- Oracle Java Tutorial: “Hello World!” for JDK 8 explains the familiar declaration and its parts; it is useful for the conventional example, not as the authority for current entry-point rules.
- Java SE 26 Language Specification, Chapter 12 defines application startup and candidate main methods.
- Java SE 26 Language Specification, Chapter 1 illustrates compiling and running a Java program.
- Oracle Java learning material explains the launcher-oriented roles of
public,static, andvoid. - Java SE 21 preview documentation records the earlier, release-specific preview rules for unnamed classes and instance main methods.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




