编译逻辑
:material-circle-edit-outline: 约 156 个字 :fontawesome-solid-code: 13 行代码 :material-clock-time-two-outline: 预计阅读时间 1 分钟
编译运行
javac Hello.java
:编译
java Hello
:编译完运行
结构
public class Hello{
public static void main(String[] args){
System.out.println("Hello, World!");
}
}
- The basic unit of a Java program is a class.
- A class called "
Hello
" is defined. - The name of the source file must be the same as the name of the class with a mandatory file extension of "
.java
".- Hence, this file MUST be saved as "
Hello.java
" - case-sensitive.
- Hence, this file MUST be saved as "
- A class called "
public static void
defines the so-calledmain()
method, which is the entry point for program execution.
流程图
Writing a Java program:
- Step 1: Write the source code "
Xxx.java
". - Step 2: Compile the source code "
Xxx.java
" into Java portable bytecode (or machine code)"Xxx.class
" using the JDK's Java compiler by issuing the command "javac Xxx.java
". - Step 3: Run the compiled bytecode "
Xxx.class
", using the JDK's Java Runtime by issuing the command "java Xxx
".
Other
Whitespaces: Blank, tab, and newline are collectively called whitespace.