This article source: http://www.zretc.com/technologyDetail/346.html
In Java, the main () method is the entry method for a Java application, that is, when the program is running, the first method to execute is the main () method, which differs greatly from other methods, such as the name of the method must be main, and the method must be public For a static void type, the method must receive a string array of arguments, and so on.
Before looking at the main () method in Java, let's look at one of the simplest Java application HelloWorld, which I'll use to illustrate the mystery of the main () method in the Java class, and the code for the program is as follows:
public class HelloWorld {public static void main (String args[]) {System.out.println ("Hello world!");}}
First, say the class:
The HelloWorld class has the main () method, which indicates that this is a Java application that starts a running program directly from the JVM (Java Virtual machine).
Since it is a class, Java allows classes to be non-public keyword constraints, although the definition of a class can only be restricted to public or unrestricted keywords (default).
Second, the main () method
The declaration of the main () method is: public staticvoid main (String args[]). This must be defined, which is the Java specification.
Why this is defined is related to the operation of the JVM.
When there is a main () method in a class, executing the command "Java class name" will start the virtual machine to execute the main method in that class.
Since the JVM is running this Java application, it first calls the main method, which does not instantiate the object of the class, but is called directly by the class name and therefore needs to be limited to publicstatic.
For the main method in Java, the JVM has a limit and cannot have a return value, so the return value type is void.
The main method also has an input parameter, type string[], this is the Java specification, the main () method must have a parameter, the class must be string[], as for the name of the string array, this can be set by itself, according to the habit, The name of this string array is generally consistent with the Mian parameter name in the Sun Java specification paradigm, named args.
Therefore, the main () method definition must be: "public static Voidmain (string[] args)"
Java Programming Development: A detailed description of the main () method in Java