Java Command Line Arguments
Java command line arguments
Command line argument is an input or argument to the program when you run the program. In Java, we can take the inputs from the console, and it can be received in the Java program. These inputs are stored as a string array in the main method.
Naturally, it is just a method that was used until Scanner function is not introduced.
There is no restriction limit of Java command line inputs so that you can specify the n number of inputs.
See at the below example
Example
class CLexample{ public static void main(String args[]){ System.out.println("first argument= "+args[0]); System.out.println("Second argument= "+args[1]); } }
Output

In the above example, I have passed x and y as arguments.
Command Line example for passing many arguments
Example2
class CLexample2{ public static void main(String arguments[]){ for(int i=0;i<arguments.length;i++) System.out.println(arguments[i]); } }
Output

As we can see in the above example, I have passed many arguments. It concludes that we can pass more than one argument in a single command line.
Parse method
It is a method that takes String as user input and converts it into various forms like Integer, Float, and Double.
Types of parse method
There are three types of parse method.
- parseInt();
- parseDouble();
- parseFloat();
The parseint() method uses the function Parseint(). It is a member function in Integer class.
The parseDouble() method uses the function ParseDouble(). It is a member function in Double class.
The parseFloat() method uses the function ParseFloat(). It is a member function in Float class.
All of the parse methods have the same syntax.
Syntax
Integer.parseInt(String s) Float.parseFloat(String s) Double.parseDouble(String s)
Example
class CLexample3 { public static void main(String args[]) { int a=Integer.parseInt(args[1]); int b=Integer.parseInt(args[0]); System.out.println(a+5); System.out.println(b+5); } }
Output
