3.6 Command line arguments

Previous Index Next 


In the void main method declartion, the method accepts an array of strings (args). This array contains the command line arguments that have been passed to the application.

For instance if the following command was executed:

java TestArguments AAAA BBBB
Then in the void main method of the TestArguments, args[0] would equal "AAAA" and args[1] would equal "BBBB".

In Java the length statement will return the number of items in the array. So the following bit of code will return the number of command line arguments passed to the void main method:

args.length
The command line parameters can be used to pass useful startup parameters or information to a java application.