Everyone knows this very well. But the thing is that
Is Java Command Line Arguments Differ from C and C++ ...?
Then the ans is 'YES'
How ...?
The command line arguments passed to a Java application are different in 'NUMBERS' and in 'TYPE' than those
passed to a C or C++ program.
Number of Parameters --
In C and C++ when you invoke a program, the system passes two parameters to it:
> argc-- The number of arguments on the command line.
> argv-- A pointer to an array of strings that contain the arguments.
On the other hand, when you invoke a Java application, the system only passes one parameter to it:
> args-- An array of Strings (just an array--not a pointer to an array) that contain the arguments.
[You can derive the number of command line arguments with this method,
array's length() ]
The First Command Line Argument
In C and C++, the system passes the entire command line to the program as arguments, including the name
used to invoke it.
EX: if you invoked a C program like this:
diff file1 file2
[Then the first argument in the argv parameter is 'diff']
In the Java, you always know the name of the application because it's the name of the class where the main
method is defined. So, the Java runtime system does not pass the class name you invoke to the main method.
Rather, the system passes only the items on the command line that appear after the class name.
EX: if you invoked a Java application like this:
java diff file1 file2
[The first command line argument is 'file1']