why is it mandatory to pass string arg[] as an argument in main method? why we cannot pass any other data type available in java? whats the importance of passing String arg[
Because by passing String arrays, we can pass all the necessary parameters like options/arguments related to the program in the form of String easily. There can be several parameters!
Also, all the other datatypes can be easily converted from String!
An example of calling a program with several parameters therefore resulting in storage of them in String array!
java Sample_Example example1 example2 example3
Arguments:
args[0]=example1
args[1]=example2
args[2]=example3
Here, you are calling Sample_Example Class and passing three parameters example1,example2 and example3 to be used by the program! So, it is always an better alternative to store them in an String array rather than other primitive data-types or in collections or in Wrapper data-types. Always we tend to make our work simpler and here Java makes it simpler for all of us by providing this facility!