CoreJavaE10V1P3.1 第3章 Java的基本编程结构-3.1 Java 最简程序

时间:2023-03-08 19:01:45

3.1Java最简程序

FirstSample.java

 public class FirstSample
{
public static void main(String[] args)
{
System.out.println("We will not use 'Hello, World!'");
}
}

1.Java的类名命名规则

  1.1 以字母开头

  1.2 是字母(广义的unicode字母)和数字的组合

  1.3 没有长度限制

  1.4 不能使用Java保留字

2.Java的类名命名规范

  Java采用骆驼命名法,即类名是以大写字母开头的名词,如有多个单词则每个单词首字母大写(例如CamelCase)

3.java源代码文件命名规则

  3.1 源代码文件名必须与public 类名名称相同

  3.2 以.java为扩展名

4.命令行编译与运行

  javac FirstSample.java

    编译后生成FirstSample.class

  java FirstSample

    自动运行FirstSample.class,注意命令中没有.class后缀

  运行编译程序时,Java虚拟机从指定的类中寻找main方法并运行。

{
System.out.println("We will not use 'Hello, World!'");
}

1. ;是语句结束的标志,而不是回车,可以把一条语句写成多行

2. object.method(parameters) 为方法调用

3.字符串使用“  ”分隔

4i.System类是个内置包中的类,该类位于java.lang包,这个包的所有类都不需要import即可使用

5i.System.out static PrintStream out

  out是个System类的成员变量  static PrintStream out

6i.System.out.println(String)  PrintStream(String fileName)

  println(String)是PrintStream的一个方法,用于向流中输出字符串并输出一个换行符。