Java Programming: Java Command Line Argument

The java code blow is an example of passing commandline argument through command prompt.

The java code blow is an example of passing commandline argument through command prompt:

class CommandLineDemo
{
public static void main(String args[])
{
//In the code below command line is assigned to the string
String s=args[0];

System.out.println(s);

}
}

Execute the above code by first compiling the program and then using interpreter to get the output of the program.

compile the program by using the following command on the command prompt:

javac CommandLineDemo.java

Now, use the interpreter to execute the program and at the same time, pass the command line argument.

java CommandLineDemo 12

One Response

09.06.17

nice to know this command…

Leave Your Response