/* related posts with thumb nails */

Command line arguments:

§ Command line arguments are the parameters passed to the executable java program in the form of strings.

§ Command line arguments are collected in main function itself.

§ The argument is an array of strings and can collect the list of strings

§ File name is not included in the list of arguments as in C language.

§ This is very useful to receive quick inputs

In the following example Test.java, “as[]” is an array of strings used to collect command line arguments.

class Test

{

public static void main(String as[])

{

System.out.println(“Number of arguments=”+as.length);

for(int i=0;i

System.out.println(as[i]);

}

}

We could execute the above program as follows.

c:\jdk1.5>java Test aa bb cc

The above command produces the following output:

Number of arguments=3

aa

bb

cc

Related Topics:

0 comments:

Post a Comment