Java classes run in a wider context (a specific JVM, as others have pointed out). Below are some features:
In all cases, the main() method is the canonical entry point for executing the code specified by a particular class. From the docs on java JVM:
DESCRIPTION
The java tool launches a Java application. He does this by starting the Java runtime, loading the specified class and calling this main class method. The method declaration should look like this:
public static void main(String args[])
The method must be declared public and static, it must not return any value, and must accept a String array as a parameter. By default, the first argument without a parameter is the name of the class to call. The fully qualified class name must be used. If the -jar parameter is specified, the first argument without the parameter is the name of the JAR archive containing the class and resource files for the application, and the launch class is indicated by the header of the Main-Class manifest.
The Java runtime looks for the launch class and other classes in three sets of locations: the bootstrap class path, installed extensions, and the user class path.
Arguments without a parameter after the class name or JAR file name are passed to the main function.
The javaw command is identical to java, except that there is no console window associated with javaw. Use javaw when you do not want the command prompt window to appear. However, the javaw launcher displays a dialog box with error information if for some reason the launch is not possible.
You declare:
In the above code, when return is used, it should return to the function that calls the main function.
There can be no other Java function (in fact, usually not) that calls the main() function. This is an agreement to declare a known entry point. If the JVM is started to run your main() class, then when main() returns, the JVM exits, except in a few special cases, for example. there are other threads not related to demons, or there is a stop hook.