O'Reilly logo

Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition by Rolf W. Rasmussen, Khalid A. Mughal

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

3.23. Program Arguments

Any arguments passed to the program on the command line can be accessed in the main() method of the class specified on the command line:

java Colors red green blue

These arguments are called program arguments. Note that the command name, java, and the class name Colors are not passed to the main() method of the class Colors.

Since the formal parameter of the main() method is an array of String objects, individual String elements in the array can be accessed by using the [] operator.

In Example 3.8, the three arguments "red", "green", and "blue" can be accessed in the main() method of the Colors class as args[0], args[1], and args[2], respectively. The total number of arguments is given by the field length of the String ...

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