sir kindly tell me Which of the following are valid syntax for the main() method required by a Java application? & why
A. public static void main(String args[]){} B. static public void main(String args[]){} C. static public void main(String[] args){} D. public static void main(String[] args){} E. static public void main(String args){}
(E) is invalid, as the main method in Java should accept a single array of string as parameter, in this case (E) is just an ordinary static method named main that accept string as parameter.
Aswer (A) to (D) is a valid main method in Java. We can write String[] args or String args[] as the parameter.
Because in C they had the concept of a main file which controls the rest of the programming, and it had a method in called main whihc the compiler and runtime look to to start the program off.
Because Java is derived from C via C++
because they told the JVM to look for a method called main
Becuase there is nowhere for it to return a result or value to (hence "void").
Because access is required from outside the class, it has to be "public"
Because access is needed before an object is created, it has to be "static"
Because one can write "static public" as a synomym for "public static," but please stick to "public static."
Because the command line passes an array of Strings to the main method.
Because one can write String[] args, String args[], or (I think) String ... args as synomyms, but String[] is best because it confirms that the object passed has a String-array type.
And you can use another identifier instead of args (argv and arguments appear in older sources), but again, please stick to "args."
CR
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
a bit of art, as a gift, that will fit in a stocking