第一个程序Hello World
-
首先在D盘创建一个 新建文本文档.txt 文件,然后对其改名为Test.java
-
使用记事本打开Test.java文件,输入以下文本:
public class Test{ public static void main(String[] args){ System.out.print("Hello World"); } }
注意:class后面接的类名需要和文件名称保持一致
保存文件
-
使用win + R进入DOS界面
进入到D盘
使用javac Test.java进行编译文件
-
使用dir命令查看文件是否编译成功,成功会多出一个文件Test.class
-
运行编译后的文件
第一个程序小结
- Java源文件以
java
为扩展名,源文件的基本组成部分是类(class),如本类中的Test类 - Java应用程序的执行入口是main()方法,它有固定的书写格式:public static void main(String[] args) {……}
- Java语言严格区分大小写
- Java方法由一条条语句构成,每个语句以
;
结束 - 括号都是成对出现的,缺一不可