[Java Basics] Complete tutorial on JDK download, installation and environment configuration

1.jdk download
2.Install jdk
  • The default installation of jdk is directly installed onc盘不需要修改直接一直点下一步,
  • If you want to install to another disk, create onejava的文件夹, 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:

  1. The first step is to installjdk. Directly select the created jdk1.8.0_231 file installation path and wait for the installation to complete
    Insert image description here

  2. The second step is to installjre. Directly select the installation path of the created jre1.8.0_231 file and wait for the installation to complete
    Insert image description here

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
      Insert image description here
  • AddCLASSPATH, fill in the value corresponding to CLASSPATH.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar
    Insert image description here

  • Add after Path,%JAVA_HOME%\bin和%JAVA_HOME%\jre\bin
    Insert image description here
    Insert image description here

4. Verify whether the jdk configuration environment variables are configured successfully
  • Use win+r to output cmd and enter in the cmd windowjava -versionThe following figure indicates that the jdk environment is configured successfully

Insert image description here

5. The role of configuring environment variables
JAVA_HOME
  • Convenient configurationpath和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 passjavac编译再java执行. However, commonly used executable files such as javac, java, etc. are placed in JDK安装目录下的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 write improt java.util.*时, the compiler needs to know when facing the import keyword You have to import java.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下.

Guess you like

Origin blog.csdn.net/qq877728715/article/details/133941598
Recommended