O'Reilly logo

Java™ Phrasebook by Timothy Fisher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing Command-Line Arguments

java my_program arg1 arg2 arg3
											public static void main(String[] args) {
											String arg1 = args[0];
											String arg2 = args[1];
											String arg3 = args[2];
											}

In this phrase, we store the values of three command line arguments into three separate string variables, arg1, arg2, and arg3.

Any java class can have a main() method, which is executable from the command line. The main() method accepts a String array of command-line arguments. The arguments are contained in the array in the order in which they are entered at the command line. So, to retrieve the command-line arguments, you simply have to extract the elements of the arguments array passed into the main() method.

If your application uses a lot of command-line arguments, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required