Dabai became the second day of Java software siege lion (Java program compilation and running, JDK, JRE, JVM relationship, environment variables, HelloWorld program)

The programming phase of a Java program

1. Java loading and execution

*The operation of a Java program includes two very important stages
-compilation stage
-operation stage

* Compile stage

The main task of the compilation phase is to check whether the Java source program conforms to Java syntax

A normal bytecode file (.class)
can be generated if it conforms to the Java grammar

Bytecode files are not purely binary, and such files cannot be executed directly in the operating system. How to use
javac.exe (Java compiler, which comes with JDK)
? Where is it used?
Use in the DOS command window.
**Javac usage rules:** javac java source file path

The class file is the final file to be executed, so after the class file is generated, the deletion of the java source file does not affect the execution of the java program.
*After compiling, you can copy the class file to other operating systems to run. [Cross-platform]

* After the JDK is installed in the runtime phase
, in addition to the built-in javac.exe, there is another tool called java.exe, which is mainly responsible for the runtime phase.

Where is java.exe used? how to use?
-Use in DOS window
-How to use Enter java class name

The java.exe command will start the Java Virtual Machine (JVM), and the JVM will start the class loader ClassLoader.
ClassLoader will search for the A.class file on the hard disk. If the file is found, the bytecode file will be loaded into the JVM.
The JVM interprets the A.class bytecode file into binary.
Then the operating system executes the binary and interacts with the underlying hardware platform.

2. The relationship between JDK, JRE, and JVM

JDK : The development toolkit provided by developers is for program developers. It includes a complete jre, Java operating environment, and other toolkits for developers.

JRE: The environment required by the runtime package dependencies are all in jre

JVM: When we run a program, JVM is responsible for converting bytecode into specific machine code. JVM provides memory management, garbage collection, and safety mechanisms. It is independent of hardware and operating system. It is exactly that java programs can be written more than once. Reason for execution

Introduction to the JDK directory:
JDK/bin: This directory stores many commands, such as javac.exe and java.exe
javac.exe is responsible for compiling
java.exe and running

Develop HelloWorld program

//public表示一个公开的
//class表示一个类
//HelloWorld表示一个类名
public class HelloWorld{
    
    //表示定义一个公开的类,起名HelloWorld
//类体中不允许直接编写Java语句(除声明变量之外)
/*
	public表示公开的
	static表示静态的
	void表示空
	main表示方法名是main
	(String[] args)是一个main方法的形式参数列表
	需要记住的是:以下的方法是一个程序的主方法。是程序的执行入口,是一个固定编写方式。
*/
	public static void main (String[] args){
    
    //表示定义一个公开的静态的主方法
	//方法体
	//方法体

	//Java语句以";"终止,分号必须是半角分号
		System.out.println("Hello World!");//向控制台输出语句
	}
}

Compile the HelloWorld.java source program with the javac tool: The
first problem to be solved is: Is the javac command available?
Open the DOS command window and directly enter javac

* Important
PATH environment variable configuration
* Note: The path environment variable has nothing to do with the java language. The path environment variable is a knowledge point of the windows operating system. The path environment variable is specifically to guide the windows operating system. ·

Guess you like

Origin blog.csdn.net/qq2632246528/article/details/112273678