我们先从 hello world 开始,看看 Java 代码的基本结构是什么。Java 是面向对象语言,在 Java 中一切皆对象,因此 hello world 也需要使用面向对象来实现。如下的 hello world,包括 class 定义、main 方法、main 入参、打印输出、注释内容等。
/** * 定义 Hello 类型 **/ public class Hello { /** * 定义程序入口 main 方法 **/ public static void main(String[] args) { // 向屏幕输出文本:Hello, world! System.out.println("Hello, world!"); } }
以上的 hello world 虽然简单,但是也需要遵守 Java 语言的规范,包括但不限于:
© 2016 - 2024 chengxuzhixin.com All Rights Reserved.