Command Line Arguments
- A Java application can be passed string arguments when it is executed.
- These are called
command line arguments
and allow your programs to receive simple input from whomever is executing
your program.
When you execute your application, you can pass in values by adding
them to the end of the java command:
java MyFamily Pippi
Each separate string is an argument, so if you want to pass in a phrase,
(i.e. "Pippi the dog") you will need to quote it.
In your program, the array named
args
has the passed-in arguments.
(Remember static void main(String args[])
?)
To access these values, you just access the array.
The first argument is in args[0].
Unlike Linux, C, and C++, the first element in the array does not contain the name
of the program.