October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Java Main Method: How the Launcher Starts Your Program

The familiar Java entry point tells the launcher where to start. Here’s what each part means, how command-line arguments arrive, and why newer Java releases allow other forms.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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!");
    }
}
  1. Compile it from a terminal in the directory containing the file: javac Test.java.
  2. Run the compiled class: java Test.
  3. To pass arguments, add them after the class name, as in java Test Hello, world.. The values after Test are passed to the program as strings.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Java 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.

Official references

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.