Command-Line Handling
- 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.
- To access these values, you just access the array.
- The first argument is in args[0].
- Unlike C, C++, and Linux Shellscripts, the first element in the array does not contain the name
of the program.