command line arguments java code example

Example 1: java command line arguments

class CommandLineExample{  
public static void main(String args[]){  
System.out.println("Your first argument is: "+args[0]);  
}  
}

//Now follow these steps
compile by > javac CommandLineExample.java  
run by > java CommandLineExample sonoo

Example 2: command line arguments in java

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