本文介绍了谁在java中调用main函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public static void main(String[] args)
{
boolean t=true;
System.out.println("Before return");
if(t) return;
System.out.println("not execute");
}
在上面的代码中返回然后它应该返回调用main函数的函数。究竟是谁调用
main
函数?
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类在内执行更大的上下文(特别是其他人注意到的JVM)。以下是一些可能性:
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.SomeClass
- 你运行
java -jar somejar.jar
(将在.jar文件的清单中选择相关课程。) - 您正在使用Eclipse并使用debug / run来执行特定类的
main()
方法。
you run
java -cp {classpath here} com.example.foo.SomeClass
to explicitly select a class for the java application launcher to runyou run
java -jar somejar.jar
(the class in question will be selected in the .jar file's manifest)you are working within Eclipse and use debug/run to execute a particular class's
main()
method.
在所有情况下,
main()
方法是在给定特定类的情况下执行代码的规范入口点。来自 java
JVM上的文档:
java工具启动Java应用程序。它通过启动Java运行时环境,加载指定的类以及调用该类的main方法来实现此目的。方法声明必须如下所示:
public static void main(String args[])
Java运行时在三组位置中搜索启动类和其他使用的类:引导类路径,已安装的扩展和用户类路径。
Non-option arguments after the class name or JAR file name are passed to the main function.
这篇关于谁在java中调用main函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!