Java Reference
In-Depth Information
LISTING 8.10
//********************************************************************
// NameTag.java Author: Lewis/Loftus
//
// Demonstrates the use of command line arguments.
//********************************************************************
public class NameTag
{
//-----------------------------------------------------------------
// Prints a simple name tag using a greeting and a name that is
// specified by the user.
//-----------------------------------------------------------------
public static void main (String[] args)
{
System.out.println ();
System.out.println (" " + args[0]);
System.out.println ("My name is " + args[1]);
}
}
OUTPUT
> java NameTag Howdy John
Howdy
My name is John
> java NameTag Hello Bill
Hello
My name is Bill
Remember that the parameter to the main method is always an array of String
objects. If you want numeric information to be input as a command-line argu-
ment, the program has to convert it from its string representation.
You also should be aware that in some program development environments, a
command line is not used to submit a program to the interpreter. In such situa-
tions, the command-line information can be specified in some other way. Consult
the documentation for these specifics if necessary.
 
Search WWH ::




Custom Search