Java Command Line Argument


In the java program, you can pass the argument through java command-line argument at runtime. The arguments passed from the console which as an input in the java program.

You can pass 'n' numbers of arguments from the command prompt.

Java commandline argument

Example 1:-

You must pass at least one argument through the command prompt.

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

 compile > javac CommandLine.java  
run > java CommandLine welcome 

Example 2:-

You can pass 'n' numbers of arguments through the command prompt.

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

compile > javac CommandLine1.java  
run > java CommandLine Welcome To Onlinetpoint  



Onlinetpoint is optimized for basic learning, practice and more. Examples are well checked and working examples available on this website but we can't give assurity for 100% correctness of all the content. This site under copyright content belongs to Onlinetpoint. You agree to have read and accepted our terms of use, cookie and privacy policy.