+ 1

[DUPLICATE] Is it necessary to write "String [ ]args" in the main method?

And if yes then how do we accept an integer by function argument?

10th Dec 2016, 3:06 PM
Anand Chourasiya
Anand Chourasiya - avatar
1 Answer
0
Java can have different starting points depending on which context it's run. If it's an Applet, it will run some class extending Applet. If it's a server servlet, it will extend the Servlet interface. For a command line, it keeps the legacy interface similar to the C's "int main(int argc, char* argv[])". FROM SOURCES : In order for this to happen, the definition of this main method must be, public static void main(String args[]) The fact that this string array is called args is a standard convention, but not strictly required.  Now comming back to your question Yes you can pass it as int because everything passed into main method, the one used by the JVM to start a program, is a String, everything. It may look like the int 1, but it's really the String "1", and that's a big difference.
10th Dec 2016, 3:17 PM
Vipul Walia
Vipul Walia - avatar