Command Line Arguments in Java

Command line argument in java highlights the issued, which allow you to affect the operation of an application during the process.

Command Line Arguments in Java

The ongoing Java application can accept any number of arguments from the command line but it is command line argument, which allow the user to affect the operation of an application. In fact, the command-line argument is an argument, which passed at the time of running of the Java program, which can be received iin, the program and used as an output.

Command line argument provides an convenient way passage to check out the behaviour of the program on different values.

It can be better understand by the example. Suppose program named CmndLineArguments that accept command line arguments as a string array and echo them on standard output device.

java CmndLineArguments Mahendra zero one two three.

* How to use command line arguments in java program.
class CmndLineArguments {

public static void main(String[] args) {
int length = args.length;
if (length <= 0) {
System.out.println("You need to enter some arguments.");
for (int i = 0; i < length; i++) {

Output of the program:

Run program with some command line arguments like:

java CmndLineArguments Mahendra zero one two three


Command line arguments were passed :






Important points regarding Command Line Argument

  • It can be used to specify configuration information while launching your application.
  • The major feature about it is that there is no restriction on the number of command line argument.
  • Commans Line Argument allow many applications that accept it and allow the user to specify various combinations of arguments in various orders.