Introduction
In this article, we discuss command line arguments in Java.
What is command line argument
An argument passed when a Java program is run is called a command line argument. The arguments can be used as input. So, it provides a convenient way to check out the behavior of the program on various values. We can pass any number of arguments from the command prompt or nearly anywhere a Java program is executed. This allows the user to specify configuration information when the application is launched.
Advantages
- We can provide any number of arguments using a command line argument.
- Information is passed as Strings. So we can convert it to numeric or another format easily.
- While launching our application it is useful for configuration information.
1. Example
In this example, we are printing the first command line argument as in the following.
CommandLineEx.java
- class CommandLineEx {
- public static void main(String x[]) {
- System.out.println("First Command line Argument is: " + x[0]);
- }
- }

2. Example
In this example, we are printing or showing all the command-line arguments using a for loop.
CommandLineEx1.java




Sharad GuptaPosted Aug 4, 2013, 11:04 PM
nice one