Java Reference
In-Depth Information
As long as Java can find the class, your program uses it when it runs. Note, however, that
only the starting-point class needs a main() method. After it is called, the methods inside
the various classes and objects used in your program take over. Although you can include
main() methods in helper classes, they are ignored when the program runs.
Java Applications and Command-line
Arguments
Because Java applications are standalone programs, it's useful to pass arguments or
options to an application.
You can use arguments to determine how an application is going to run or to enable a
generic application to operate on different kinds of input. You can use program argu-
ments for many different purposes, such as to turn on debugging input or to indicate a
filename to load.
Passing Arguments to Java Applications
How you pass arguments to a Java application varies based on the computer and virtual
machine on which Java is being run.
To pass arguments to a Java program with the java interpreter included with the JDK,
the arguments should be appended to the command line when the program is run. For
example:
java EchoArgs April 450 -10
In the preceding example, three arguments were passed to a program: April , 450 , and -
10 . Note that a space separates each of the arguments.
To group arguments that include spaces, the arguments should be surrounded with quota-
tion marks. For example, note the following command line:
java EchoArgs Wilhelm Niekro Hough “Tim Wakefield” 49
Putting quotation marks around Tim Wakefield causes that text to be treated as a single
argument. The EchoArgs application would receive five arguments: Wilhelm, Niekro,
Hough, Tim Wakefield, and 49. The quotation marks prevent the spaces from being used
to separate one argument from another; they are not included as part of the argument
when it is sent to the program and received using the main() method.
 
Search WWH ::




Custom Search