主要方法如何工作? [英] How does the main method work?

查看:76
本文介绍了主要方法如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一些破碎教学的产物,我需要一些帮助。我知道Java中有一个叫做主要方法的东西,我确信其他的编程语言。我知道你需要一个让你的代码运行,但你如何使用它来运行?它做了什么,你需要把它放进去让你的代码运行?

I'm the product of some broken teaching and I need some help. I know that there is this thing called the "main method" in Java and I'm sure other programming languages. I know that you need one to make your code run, but how do you use it to make your run? What does it do and what do you need to have it put in it to make your code run?

我知道它看起来应该是这样的。
但几乎没有。

I know it should look something like this. But almost nothing more.

static void main(String[] args){

}


推荐答案

针对一般情况逐点打破这一点:

Breaking this down, point-by-point, for the general case:


  1. 所有Java应用程序都以 main()方法开始处理;

  2. main 中的每个语句按顺序执行,直到达到 main 的结尾 - 这是当你的程序终止时;

  3. static 是什么意思? static 表示您不必实例化类来调用该方法;

  4. String [] args是一个 String 对象的数组。如果要在命令行上运行程序,可以将参数作为参数传递。然后可以访问这些参数,就像访问数组中的元素一样: args [0] ... args [n] ;

  5. public 表示任何对象都可以调用该方法。

  1. All Java applications begin processing with a main() method;
  2. Each statement in the main executes in order until the end of main is reached -- this is when your program terminates;
  3. What does static mean? static means that you don't have to instantiate a class to call the method;
  4. String[] args is an array of String objects. If you were to run your program on the command line, you could pass in parameters as arguments. These parameters can then be accessed as you would access elements in an array: args[0]...args[n];
  5. public means that the method can be called by any object.

这篇关于主要方法如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆