Java – Command Line Argument

Home/Java - Tutorial/Java - Classes and Methods/Java – Command Line Argument
Java – Command Line Argument 2017-08-09T11:21:47+00:00

Java Command Line Argument :

Sometimes you will want to pass information into a program when you run it. This is accomplished by passing command-line arguments to main( ).
A command-line argument is the information that directly follows the program’s name on the command line when it is executed.
To access the command-line arguments inside a Java program is quite easy—they are stored as strings in the String array passed to main( ).

?

 


Try executing this program, as shown here:
java CommandLine this is a test 100 -1
When you do, you will see the following output:
args[0]: this
args[1]: is
args[2]: a
args[3]: test
args[4]: 100
args[5]: -1
But first of all you should have the basic knowledge about command line and how any java program run through command prompt. CLICK HERE to know more.

Prev Next