This problem has plagued me for a long time, today on a check, after all, my curiosity is more heavy
1. Why ' public '
Because Java programs are called through the JVM virtual machine, the main () function must be public if it wants to be called
2.why "Static"
In Java, there is no static variable or function, if you want to be called, it is necessary to create a new object before you can. The main function, as the entrance to the program, needs to be started before other functions are instantiated, which is why it is added a static. The main function is like a door, to explore other functions to enter the program from the door first. Static provides an attribute that can be started without having to establish an object.
3.why "(string[] args)"?
(1) First of all, why this string array to call "args", in fact, this is a convention of a naming, not called "args" called Other is OK, do not believe that they can test themselves.
(2) To see why if a string array, Java is running like this (below), a bit like the command line, A1,A2,A3 is the command in this string array.
Java main A1 A2 A3
Let's go deep into the JVM driver and see how the main () function is started:
Mainid = (*env)->getstaticmethodid (env, MainClass, "main", "([ljava/lang/string;) V");
This is the JVM startup code, go directly to the static, parameter is a string array of the Main method.
/********************************
* This article from the blog "Bo Li Garvin"
* Reprint Please indicate the source : Http://blog.csdn.net/buptgshengod
******************************************/
Why is the main function of Java a public static void main (string[] args)