欢迎光临散文网 会员登陆 & 注册

【Day-2】Java自学笔记 - HelloWorld

2023-01-03 00:18 作者:浩泪  | 我要投稿

1.Java程序的过程能够被简化为三步:

在文本编辑器输入和把它保存成文件 - HelloWorld.java

terminal窗口编译这个文件 - javac HelloWorld.java

• terminal窗口运行这个文件 - java HelloWorld.java

2.Hello World

Ouput: 

3.分析一下上面的代码

时间复杂度:O( 1 ).   // 待分析

空间复杂度:O( 1 ).   // 待分析

<1>. class定义 - 使用Class关键字来声明了一个新类

<2>. HelloWorld - 类名

<3>. main方法

在Java编程语言中,每一个应用都应该包含一个main方法。main方法时Java程序的主入口而且它是强制性的。

• public :JVM无论在哪都可以执行main方法

• static :  主要方法是在没有对象的情况下调用。修饰符public和static可以按任意顺序编写 . [ ? ]

• void : main方法没有返回任何东西

• main() : JVM中配置的名称。main方法必须在类定义内。编译器总是从主函数开始执行代码。[ Name configured in the JVM. The main method must be inside the class definition. The compiler executes the codes starting always from the main function. ] 

• String[] : main方法接受单个参数,即String类型的元素数组。

4. 注意点

•  程序定义的类名为HelloWorld,与文件名(HelloWorld.java)相同。这不是巧合。在Java中,所有代码都必须驻留在一个类中,并且最多有一个公共类包含main()方法。【 The name of the class defined by the program is HelloWorld, which is the same as the name of the file(HelloWorld.java). This is not a coincidence. In Java, all codes must reside inside a class, and there is at most one public class which contains the main() method.

•  按照惯例,主类(包含主方法的类)的名称应该与保存程序的文件的名称匹配。【 By convention, the name of the main class(a class that contains the main method) should match the name of the file that holds the program.

•  每个Java程序都必须有一个与文件名匹配的类定义(类名和文件名应该相同)。【 Every Java program must have a class definition that matches the filename (class name and file name should be same). 】

5. sout

System.out.println("Hello, World"); - 可以通过在idea里打sout快速生成。这个会在控制台输出Hello,World


【Day-2】Java自学笔记 - HelloWorld的评论 (共 条)

分享到微博请遵守国家法律