Home >Java >Javagetting Started >In-depth analysis of the first java program
When we learn java programming, the first Java program we start with is HelloWorld. Now let's go back and analyze the program in depth.
(Learning video sharing: java teaching video)
There are three steps to successfully run a Java program: write, compile, run
Write:
public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }
Compile:
javac HelloWorld.java
Run:
java HelloWorld
Summary of the first Java program
1. Java program writing— Compilation-running process
编写:将编写的代码保存在一个以".java"结尾的源文件中; 编译:使用javac命令编译java源文件,这将会生成一个以".class"结尾的字节码文件,格式:javac 源文件名.java 运行:使用java命令解释运行由javac生成的以".class"结尾的字节码文件,格式:java 类名
2. Class declaration
You can declare multiple classes in a java source file, but at most one class can be declared public, and this is required The class name of a class declared as public must be the same as the source file name.
3. The entrance of the program
The entrance of the program is the main method, and the fixed format is:
public static void main(String[] args) { ... }
4. Output statement
System.out.print(); //只输出 System.out.println(); //先输出后换行
5. Execution statement The end of
Each line of execution statement ends with ";"
6. Comments
Categories: single-line comments, multi-line comments, document comments
Format:
Single-line comments: //
Multi-line comments: /* …*/
Documentation comments: /**…*/
Java API Documentation
Java API documentation is a description of how to use the class library provided by java. You can directly enter the API provided by Oracle's official website to view and use it.
Related recommendations: java introductory tutorial
The above is the detailed content of In-depth analysis of the first java program. For more information, please follow other related articles on the PHP Chinese website!