Install Java environment on Windows system

1. Install jdk.
Different packages are installed on different platforms:
Oracle official download .
Oracle official versions
recommend installing jdk1.8
for 32-bit operating system: prepare jdk-xxx-windows-i586.exe
64-bit operating system: prepare jdk-xxx-windows- x64.exe
downloaded jdk:
Insert image description here
Steps:
1. Double-click the jdk-8u371-windows-x64.exe file to execute the installation.
2. Click Next
Insert image description here
3. Click Next
Insert image description here
Insert image description here
4. You can change the directory, or you can directly go to the next step
Insert image description here
Insert image description here
5. After the installation is complete, click Close
Insert image description here
2. Configure environment variables
1. JAVA_HOME environment variable configuration
1.1 Reason for configuration:
JAVA_HOME environment variable, the value is the installation directory of JDK. Some tools and open source software developed based on Java will use the JDK path, use To find the Java environment on the machine, such as tomcat, eclipse, so we configure the JDK path to JAVA_HOME.
1.2 Configuration method
(1) Path: My Computer –> Right-click the mouse, click Properties –> Advanced System Settings –> Environment Variables
Insert image description here
Insert image description here
Insert image description here
(2) Add the system environment variable JAVA_HOME. The variable value is the JDK installation directory in your computer.
Insert image description here

2. PATH environment variable configuration
2.1 Configuration reason
: After the JDK is installed, the two important execution files javac.exe (code compilation file) and java.exe (code execution file) exist in the bin directory of the installed JDK, and we Java written or other people's programs run are usually placed in a new directory, mainly to facilitate management. If they are placed here, it will be very confusing, not to mention the compilation and generation of class files.

However, when we want to run a Java program, we need to compile (need to use javac.exe) and execute (need to use java.exe), and the system default is to look for these two execution files in the folder directory where the current program is located. , instead of looking elsewhere, at this time we need to configure the Path environment variable so that every time the program runs, it will automatically go to the bin directory where the JDK is installed to search for javac.exe and java.exe files.
2.2 Configuration method
(1) Find the PATH variable in the system variables, double-click the variable name to enter editing
Insert image description here
(2) Click New, find the directory where javac.exe and java.exe are located in the JDK installation directory, copy the directory here, and click Confirm That’s it, the Path path is set.
Insert image description here
Note:
Since JAVA_HOME configures the JDK installation directory, Path has another configuration method, as follows:
%JAVA_HOME%\bin
1. Among them, % % represents the value that refers to JAVA_HOME
2. The advantage of this is that if the Java installation directory occurs If it changes,
you need to modify the value of JAVA_HOME. There is no need to modify the value of the Path variable.
3. In some Windows 10 systems, the %JAVA_HOME%\bin configuration becomes invalid after restarting.
The solution here is to configure the full path according to the method above.

Note:
The Path variable configuration of Windows 8 and 10 is more friendly. Just configure a record directly. If it is Windows 7, you need to use; (English semicolon) to separate the value of the Path variable, and then append the Java installation directory. bin directory path is enough

3. CLASSPATH environment variable configuration method
3.1 Configuration reasons
CLASSPATH, as the name suggests, is the package path, which tells Java where to find the required packages and classes for use by the program during execution. Therefore, the path of the package should be assigned to CLASSPATH during configuration.
3.2 Configuration method
We create a new CLASSPATH in the system variable and assign the value as follows:
.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar

Insert image description here
There are three paths assigned at this time, separated by semicolons. The first English period represents the current directory path, the second directory is the tools tool package path in the lib library, and the third is the dt in the lib library. package path.

3. Verification
After installing the JDK and the corresponding configuration, you need to verify whether the installation is successful and whether the configuration is normal.
Step 1: Open the cmd command line window and press win+r on the keyboard; enter cmd to open the command line.
Step 2: Output the java -version command. If the output is as shown below, it means the installation and configuration are successful. Otherwise, you need to check whether the installation and configuration are correct.
Insert image description here

Guess you like

Origin blog.csdn.net/bigge_L/article/details/131945604