Home Java Javatutorial Command Line Arguments in Java
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Command Line Arguments in Java

Advertisement
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.

CmndLineArguments.java

/**
* 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++) {
System.out.println(args[i]);
}
}
}

Output of the program:

Run program with some command line arguments like:

java CmndLineArguments Mahendra zero one two three

OUTPUT

Command line arguments were passed :

Mahendra

zero

one

two

three

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.
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 3, 2013

Related Tutorials

Ask Questions?    Discuss: Command Line Arguments in Java  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com