Article directory
1.jdk download
- Download address:https://www.oracle.com/java/technologies/downloads/#java8-windows
- Note: Downloading here requires
oracle账号
. If you don’t have an account, register first or download it from other websites
- Note: Downloading here requires
2.Install jdk
- The default installation of jdk is directly installed on
c盘不需要修改直接一直点下一步
, - If you want to install to another disk, create one
java的文件夹
, and create two folders under the java folderjdk1.8.0_231和jre1.8.0_231
(add versions of jdk and jre respectively You can directly see the installed version)
Installation is in two steps:
-
The first step is to install
jdk
. Directly select the createdjdk1.8.0_231
file installation path and wait for the installation to complete
-
The second step is to install
jre
. Directly select the installation path of the created jre1.8.0_231 file and wait for the installation to complete
3. Configure jdk environment variables
Right-click "This Computer" on the desktop ->Properties ->Advanced System Settings ->Environment Variables ->System Variables (configured here系统变量
means this This variable can be used by all users of the computer, 用户变量
can only be used by the currently logged in user)
-
JAVA_HOME和CLASSPATH
is a new environment variable, is in the original oneAdd later (do not create a new path environment variable)path
环境变量
- Add JAVA_HOME, fill in the jdk installation path with the value corresponding to JAVA_HOME
- Add JAVA_HOME, fill in the jdk installation path with the value corresponding to JAVA_HOME
-
Add
CLASSPATH
, fill in the value corresponding to CLASSPATH.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar
-
Add after Path,
%JAVA_HOME%\bin和%JAVA_HOME%\jre\bin
4. Verify whether the jdk configuration environment variables are configured successfully
- Use win+r to output cmd and enter in the cmd window
java -version
The following figure indicates that the jdk environment is configured successfully
5. The role of configuring environment variables
JAVA_HOME
- Convenient configuration
path和classpath的变量值
. Even when you本地的JDK的路径
change, just go修改JAVA_HOME的配置路径即可。
- For some software written based on java, when these software are running,
可以更好的找到虚拟机的路径
.- For example, Eclipse is written in Java, so it must require the existence of a virtual machine when running. Then Eclipse can find the directory of the virtual machine through this configuration variable.
Path
When you ask the system to run a program without telling it the full path of the program, in addition to looking for the program in the current directory, the system will also go to< a i=2>. path中指定的路径去寻找
- Java program needs to pass
javac编译再java执行
. However, commonly used executable files such as javac, java, etc. are placed inJDK安装目录下的bin目录
, so they need to be . The bin directory under the jdk installation directory is added to the existing PATH variable
CLASSPATH
- CLASSPATH tells the Java execution environment in which directories the classes or packages required for the Java program you want to execute can be found.
它的作用与import、package关键字有关
, when writing java source code, you will refer to tool classes provided by others. For example, when you writeimprot java.util.*时
, the compiler needs to know when facing the import keyword You have to importjava.util这个package中的类到底在哪
.- Same as above, if not told,
他就默认在当前目录下,而如何告诉它呢?就是设置CLASSPATH
. - usually refers to two class packages, one is
dt.jar,一个是tools.jar
. Both packages are inJDK目录下的lib下
.
- Same as above, if not told,