javacodex.com
Java Examples
Java Examples
memu home questions

Command Line Arguments

When the program is launched, the jvm passes the command-line arguments to the programs main method via an array of Strings.

Source: (CommandLine.java)

public class CommandLine {
   public static void main(String[] args) {
      System.out.println("Total args: " + args.length);
      for (String s: args) {
         System.out.println(s);
      }
   }
}
 

Output:

# java CommandLine The cat in the hat
Total args: 5
The
cat
in
the
hat

Questions answered by this page:

How To Use Command Line Arguments in java? Passing command arguments to a Java program. Java Program Invocation and Command-Line Arguments.

Related Examples:


Contact: javacodex@yahoo.com