Why does Java configure environment variables and how to configure environment variables

Before the environment variable is configured, use cmd to execute the Java file, you need to specify the Java executable file, otherwise it will not run.

The configuration environment is to facilitate the execution and control of Java programs without switching the executable file directory.

Then the environment variable is to let the system directly find the executable file according to the parameters of the environment variable.

 

The difference between system variables and user variables

 User variables affect the current user, while system variables affect all users. In order to make some modifications for yourself to affect other users. So set user variables to avoid affecting other users.

If both are set, the system variable configuration will be preferred.

 

Steps to configure environment variables:

Step 1: Right click on my computer - properties - advanced system settings
Step 2: System Variables -- New -- JAVA_HOME -- the directory of your installed JDK -- C:\Program Files\Java\jdk1.8.0_73
Step 3: System variables --- New -- CLASSPATH, the value is: .;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar
Notice that there is a dot in front.
Step 4: Select System Variables ---Path -- Edit -- Add the following code at the end of PATH : %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin, pay attention to be sure to add a semicolon before adding.
 
java -version Check if it is installed!

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325045326&siteId=291194637