Java Fundamentals  «Prev 


Java MainTest program

The MainTest program shows how the args array is used to access command line arguments.
Compile it and run it with the following command line:
java MainTest zero one two three
It displays the following output:
args.length: 4
args[0]: zero
args[1]: one
args[2]: two
args[3]: three

class MainTest {
 public static void main(String[] args) {
  System.out.println("args.length: "+args.length);
  for(int i=0;i<args.length;++i)
   System.out.println("args["+i+"]: "+args[i]);
 }
}