on Leave a Comment

Command Line Arguments in Java Programming

Command line arguments are the arguments that are passed to the program at the time of invoking it for execution. These java command line arguments are stored in String array (args) of main() method. Command line arguments are stored as strings. We can pass any number of arguments. 

Example of Command Line Arguments in Java

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

OUTPUT:


D:\programs>javac cmdarg.java
D:\programs>java cmdarg "alpha" "beta"
You have entered following strings:
alpha
beta

0 comments:

Post a Comment