加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

可以在哪里找到Java主函数

发布时间:2020-12-15 02:00:36 所属栏目:Java 来源:网络整理
导读:public static void main(String [] args)是否是由 Java提供的某些类的内置或用户定义或重写函数?如果在某个接口或类中声明或定义它,可以在哪里找到它的声明? 解决方法 JLS 12 The Java Virtual Machine starts execution by invoking the method main of
public static void main(String [] args)是否是由 Java提供的某些类的内置或用户定义或重写函数?如果在某个接口或类中声明或定义它,可以在哪里找到它的声明?

解决方法

JLS 12

The Java Virtual Machine starts execution by invoking the method main of some specified class,passing it a single argument,which is an array of strings.

每个Java应用程序都应该有一个main()方法,JVM将在启动应用程序时查找main()方法.这是执行开始的地方.不,它不是内置的,你在类中定义main()方法,它成为应用程序的起始执行点. main()方法必须是public,static,return void,并接受一个参数:一个String数组.具有这种main()方法的任何类都可以用作Java应用程序的起点.

JVM spec 5.2:

The Java Virtual Machine starts up by creating an initial class,which is specified in an implementation-dependent manner,using the bootstrap class loader (§5.3.1). The Java Virtual Machine then links the initial class,initializes it,and invokes the public class method void main(String[]). The invocation of this method drives all further execution. Execution of the Java Virtual Machine instructions constituting the main method may cause linking (and consequently creation) of additional classes and interfaces,as well as invocation of additional methods.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读