public static void main(String[] args)
{
boolean t=true;
System.out.println("Before return");
if(t) return;
System.out.println("not execute");
}
In the above code when the return is used then it should return to the function which calls the main function. Who exactly calls the main function?
Java classes are executed within a larger context (a particular JVM as others have noted). Below are some possibilities:
java -cp {classpath here} com.example.foo.SomeClassto explicitly select a class for the java application launcher to runjava -jar somejar.jar(the class in question will be selected in the .jar file’s manifest)main()method.In all cases the
main()method is the canonical entry point to executing code given a particular class. From the docs on thejavaJVM:You state:
There may not be any other Java function (in fact there usually isn’t) which calls the
main()function. It’s the convention for declaring a well-known entry point. If the JVM is launched to run your class’smain()method, then whenmain()returns, the JVM exits, except in a few special cases, e.g. there are other non-daemon threads running or there is a shutdown hook.