Sending Arguments to Applications

Because Java applications are run from a command line, you can send information to applications at the same time you run them. The following hypothetical example uses the java interpreter to run an application called TextDisplayer, and it sends two extra items of information to the application, readme.txt and /p:

java TextDisplayer readme.txt /p

Extra information you can send to a program is called an argument. The first argument, if there is one, is provided one space after the name of the application. Each additional argument is also separated by a space.

If you want to include a space inside an argument, you must put quotation marks around the argument, as in the following:

 java TextDisplayer readme.txt ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.