Command-Line Arguments in Java

Sometimes when you run a program you will want to pass the information. This is accomplished by passing the command-line argument to the main () method. A command-line argument is an information that, when executed, follows the name of the program directly into the command line. Accessing command-line arguments within a Java program is quite easy - they are stored in a string array as a string in the argument parameters of the main () method. The first command-line argument saves args [0], the second args [1], and so on. For example, the following program displays all the arguments of the command line with which it is called:


public class Main 
  public static void main(String[] args) 
    for(String value:args)

Try executing this program, as shown here:
java Main this is an example text

Note : All command-line arguments are passed as strings. You must manually convert numeric values to their internal forms.