When you execute the program, you specify the class that contains the main method and then command line arguments. args[0] is the first command line argument. You need to provide it when you run the program.

java -cp . com.something.Main A B C

where A is args[0], B is args[1] and C is args[2].

Answer from Elliott Frisch on Stack Overflow
🌐
Caltech
courses.cms.caltech.edu › cs11 › material › java › donnie › java-main.html
Java Program Invocation and Command-Line Arguments
In Java, args[0] is the first command-line argument to the program, and the name of the program itself is not available.)
🌐
GeeksforGeeks
geeksforgeeks.org › java › command-line-arguments-in-java
Command Line Arguments in Java - GeeksforGeeks
Explanation: When the program is executed using java Hello Geeks at GeeksforGeeks, the JVM stores the three command-line arguments in the args array as args[0] = "Geeks", args[1] = "at", and args[2] = "GeeksforGeeks".
Published: September 28, 2026
🌐
Medium
ahedbahri.medium.com › what-is-the-use-of-args-in-java-95a15c180e8c
What is the use of args in Java?. The interesting use of args in Java. | by Ahed Bahri | Medium
February 27, 2020 - public static void main (String[] args) {System.out.println(" The First argument "+args[0]); // AhedSystem.out.println(" The second argument "+args[1]); // 22System.out.println(" the first letter of the first argument "+args[0].charAt(0)); //ASystem.out.println(" the second letter of the first argument"+args[0].charAt(1)); //h// converting from string to integer int a = Integer.parseInt(args[1]); // a = 22int b = Integer.parseInt(args[2]); // b = 23int somme=a+b; // Somme = 22+23// for example this will be the result of a+bSystem.out.println("Somme : "+somme); // Somme : 45// converting from string to Floatfloat f =Float.parseFloat(args[2]); // f = 23.0System.out.println("Float : "+f); // Float : 23.0// This will also show you the argument caracter by caracter.
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › environment › cmdLineArgs.html
Command-Line Arguments (The Java™ Tutorials > Essential Java Classes > The Platform Environment)
To have Drink, Hot, and Java interpreted as a single argument, the user would join them by enclosing them within quotation marks. ... If an application needs to support a numeric command-line argument, it must convert a String argument that represents a number, such as "34", to a numeric value. Here is a code snippet that converts a command-line argument to an int: int firstArg; if (args.length > 0) { try { firstArg = Integer.parseInt(args[0]); } catch (NumberFormatException e) { System.err.println("Argument" + args[0] + " must be an integer."); System.exit(1); } }
🌐
ThoughtCo
thoughtco.com › using-command-line-arguments-2034196
Using Command-Line Arguments in a Java Application
January 20, 2019 - When arguments are passed to a Java program, args[0] is the first element of the array (value1 above), args[1] is the second element (value2), and so on.
Find elsewhere
🌐
Medium
medium.com › @AlexanderObregon › processing-command-line-arguments-in-java-applications-200ba9b7f029
Processing Command-Line Arguments in Java Applications
March 14, 2025 - The args[] array will be empty (args.length == 0). Since Java does not automatically provide a default value, accessing args[0] would throw an ArrayIndexOutOfBoundsException.
🌐
Baeldung
baeldung.com › home › java › core java › check if command-line arguments are null in java
Check if Command-Line Arguments Are Null in Java | Baeldung
January 8, 2024 - public static void main(String[] args) { if (args.length > 0) { System.out.println(args[0]); } else { System.out.println("No command line arguments were provided."); } }
🌐
Emory
cs.emory.edu › ~cheung › Courses › 170 › Syllabus › 09 › command-args.html
The command line arguments of a Java program
Java program that prints the elements in the parameter variable args: Example Program: (Demo above code) &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp · Prog file: click here ·
🌐
Emory
mathcs.emory.edu › ~cheung › Courses › 170 › Syllabus › 09 › command-args.html
Emory
Java program that prints the elements in the parameter variable args: Example Program: (Demo above code) &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp · Prog file: click here ·
🌐
CS156
ucsb-cs156.github.io › topics › java › java_command_line_arguments.html
Java: Command Line Arguments | CS156 - GitHub Pages
If you run java Main foo bar fum then args.length is 3, args[0] is "foo", args[1] is "bar", and args[2] is "fum" Command line args come in as Strings.
🌐
Coderanch
coderanch.com › t › 779973 › java › Understanding-main-method-String-args
Understanding the main method and String[] args (Beginning Java forum at Coderanch)
February 27, 2024 - There's also another way to do this in Java that was later added, but I don't want to confuse things. So in, short, "public static void main(String[] args)" says the same basic thing, only in Java. As a final note, in C, argv[0] would always be a string that indicated the path/name of the program being executed.