Command Line Arguments in Java

Pre-requisite:

1.Java installed.

Sample code to demonstrate the command line argument in Java.

File:carg.java

class carg
{
public static void main(String ar[])
{
System.out.println(”The Argument you have entered is ” +ar[0]);
}
}

Sample Output:

while running a Java file after the Successful Completion on compiling.

#java carg nice

The Argument you have entered is nice

Feel free to share your comments.

Advertisements