Java Reference
In-Depth Information
cd <path-to-project>\Java8Recipes\build\classes
Now issue a java command to execute the class, and type some arguments on the
command-line following the class name. The following example passes two arguments:
java
org.java8recipes.chapter01.recipe1_06.PassingArguments
Upper Peninsula
You should see the following output:
Arguments that were passed to the program:
Upper
Penninsula
Spaces separate arguments. Enclose strings in double quotes when you want to pass
an argument containing spaces or other special characters. For example:
java
org.java8recipes.chapter01.recipe1_06.PassingArguments
"Upper Peninsula"
The output now shows just one argument:
Arguments that were passed to the program:
Upper Penninsula
The double quotes translate the string "Upper Peninsula" into a single argu-
ment.
How It Works
All Java classes that are executable from the command-line or terminal contain a
main() method. If you look at the signature for the main() method, you can see that
it accepts a String[] argument. In other words, you can pass an array of String
objects into the main() method. Command-line interpreters such as the Windows
Command Prompt and the various Linux and Unix shells build an array of strings out
Search WWH ::




Custom Search