当前位置:网站首页>为什么需要public static void main(String[ ] args)这个方法?
为什么需要public static void main(String[ ] args)这个方法?
2022-06-11 14:11:00 【小夕Coding】
为什么需要public static void main(String[ ] args)这个方法?
public static void main(String[ ]args)为Java程序的入口方法,JVM在运行程序时,会首先查找main()方法。其中,public 是权限修饰符,表明任何·类或者对象都可以访问这个方法,static表明main()方法是一个静态方法,即方法中的代码是存储在静态存储区的,只要类被加载后,就可以使用该方法而不需要通过实例化对象来访问,可以直接通过类名.main()直接访问,JVM在启动时就按照上述方法当签名(必须有public与static修饰,返回值为void,且方法当参数为字符串数组)来查找方法的入口地址,若能找到,就执行;找不到,则会报错。void表明方法没有返回值,main是JVM识别的特殊方法名,是程序的入口方法。字符串数组参数args为开发人员在命令行状态下与程序交互提供了一种手段。
因为main是程序等待入口方法,所以当程序运行时,第一个执行的方法就是main()方法。通常来讲,要执行一个类的方法,先必须实例化一个类的对象,然后通过对象来调用这个方法。但由于main是程序的入口方法,此时还没实例化对象,因此在编写main()方法时就要求不需要实例化对象就可以调用这个方法,鉴于此,main()方法需要被定义成public与static。下列给出了在调用main()方法时传递参数的方法。
public class T
边栏推荐
- gensim.models word2vec 参数
- 【clickhouse专栏】新建库角色用户初始化
- YOLOv3学习笔记:YOLOv3的模型结构
- In depth research and analysis report on global and Chinese oleoresin product market
- Question bank and answers for 2022 tool fitter (intermediate) operation certificate examination
- [public class preview]: mxplayer Ott audio and video transcoding practice and optimization
- Powerful full text search tool anytxt searcher
- Question bank and answers of the latest national fire-fighting facility operators (primary fire-fighting facility operators) in 2022
- I have something to say about final, finally and finalize
- In depth research and analysis report on global and Chinese diet food market
猜你喜欢

Leetcode 1968. Construct an array whose elements are not equal to the average value of two adjacent elements (yes, finally solved)

Webgl programming guide learning (0)

Task manager based on Qt development

How to quickly make the title and ending with one click?

Container -- reverse content -- use of explosion, splicing, and inversion functions

Powerful full text search tool anytxt searcher

CVPR 2022 | 神经辐射场几何编辑方法NeRF-Editing

NoSQL之Redis配置与优化

MySQL create table error 1067 - invalid default value for 'update_ time‘

Three level classification display
随机推荐
My struggle: my years in foreign enterprises (II)
Question bank and answers for 2022 tool fitter (intermediate) operation certificate examination
VIM secondary replacement
Energy storage operation and configuration analysis of high proportion wind power system (realized by Matlab)
[acwing 237. program automatic analysis] parallel search + discretization
阿里一面,谈谈策略模式在项目中的使用
Introduction to reverse learning - excellent assembly debugging tool OllyDbg
2022-2028 China metal products market status research analysis and development prospect forecast report
SQL must know and know
Redis configuration and optimization of NoSQL
【Try to Hack】URL
Alibaba Cloud 3 (Soaring Falcon) x86_64(Py3.7.8) 系统 YUM源
Alibaba Cloud 3 (Soaring Falcon) x86_ 64 (py3.7.8) system Yum source
create_ Error in engine MySQL connector encryption method
Top 10 bone conduction earphones in the list, and five easy-to-use bone conduction earphones are recommended
Question bank and answers for 2022 tool fitter (intermediate) operation certificate examination
d的each与map不一致
使用cpolar远程办公(1)
In depth research and analysis report on global and Chinese smart lamp Market
2022.2.26 library management system 2 - module 2: reader management system