Using Command-Line Arguments with main method
A command-line argument is the information that follows the program's name on the command line.
The command-line arguments are stored as string array passed to main().
For example, the following program displays all of the command-line arguments:
public class Main {
public static void main(String args[]) {
for (int i = 0; i < args.length; i++)
System.out.println("args[" + i + "]: " + args[i]);
}
}
Try executing this program, as shown here:
java Main this is a test 100
When you do, you will see the following output:
args[0]: this
args[1]: is
args[2]: a
args[3]: test
args[4]: 100
Home
Java Book
Class
Java Book
Class
Methods:
- Syntax for Method Creation
- Recursion
- Method with Parameters
- Pass-by-value vs Pass-by-reference
- What is Methods Overloading
- The main() Method
- Using Command-Line Arguments with main method
- Subclasses and Method Privacy