Current location - Quotes Website - Personality signature - Why is the main method public static void?
Why is the main method public static void?
The Main method is the first method we know when we learn the Java programming language. Have you ever wondered why the main method is public, static and void? Of course, many people learn C and C++ first, but in Java, the main methods are slightly different from the former. It will not return any value. Why is the main method public, static and void? This paper tries to find some answers.

The main method is the entrance of java program. Remember, we won't discuss Servlet, MIDlet and any other container-managed java programs here. In Java kernel programming, JVM will look for public static void main (string [] args) in the class. If this method cannot be found, it will throw an error: main program terminated.

The Main method must strictly follow its grammar rules, the method signature must be public static void, and the parameter is string array type. If it is Java 1.5 and later, you can also use variable parameters: