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 a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.