Java Programming: Why do we have main method ? can this method name be changed ?
I was wondering always, why it is always main method is the starting point for the Java program.Well When i was matured enough to read the Java Specification i learnt why and whether can it be changed ? Okay Lets See !!
Why main method ?
Main method is the starting point for the java program, JVM initialize the class and invokes main method, having below listed specifications (reference 12.1.4).
- Should be named as main
- Should be public
- Should be static
- Should accept String array as argument.
- Return type is void
As based on the above specification, we can conclude that we cannot rename the main method.
Some Additional Info.!
public static void main(String args) // this is valid
public static void main(String… args) //String… this is also valid where it is available from the java 5
public static void main(String args) //This is valid but not recommended because the array brackets in the variable)