Java main functions are generally defined as follows: public static void main (String [] args)
What does each word mean? One by one: public-indicates that the method main () can be accessed by any program, including the Java technical interpreter. Static-is a keyword that notifies the compiler that main () is used for functions in the class. This keyword is necessary for main () to start running before the program does other things. Note that if the Main () method does not use the static modifier, the compilation will not go wrong, but if you try to execute this program, an error will be reported, prompting that the main () method does not exist. This is because if you execute the program directly using the command line in this way, the class containing main () is not instantiated, so its main () method does not exist, the static modifier indicates that the method is static and can be used without instantiation. Void-indicates that the return value of main () is "untyped". In fact, its return value is determined by the specific star statement in the main function. This is important because the Java programming language requires careful type checks, including checking that the called methods actually return the types declared by these methods. String args []-is a declaration of a String array. What is its return value? When we run the "HelloWorld. class" program, we don't see any array output. Why? After we run the compiled "HelloWorld. class", we directly input "java HelloWorld" in the command line. What if we add something later?
For example, if you enter "java HelloWorld name", you will find that the original name is output, and the array String args [] is used to output parameters following the class name, if you enter "java HelloWorld name age", the output will be :...... name age: String args [0] = "name", String args [1] = "age ".