JDK installation and precautions

The full English name of JDK is Java Development Kit, that is, Java Development Kit, which provides a Java development environment and operating environment. With the development environment, the written Java source code can be parsed and compiled; with the running environment, the Java program can be run. This is why we must install the JDK before doing development.

Installing JDK is easy, but there are still many beginners who fail to install it. The main reason is that I don’t understand the JDK, and I will only follow the articles on the Internet. Although the articles on the Internet have the same general steps, the details of some steps are still different. Because I know it, I don’t know the reason. There may be a problem. The purpose of writing this article is to tell you why the JDK needs to be configured this way, installed this way, and some precautions during installation, so that you can know what is happening and why you can install it successfully.

The installation steps of JDK are as follows:

  1. Download JDK
  2. Install JDK
  3. Configure JDK
  4. Test JDK

Download JDK

You must go to the Oracle official website to download the JDK. Don't download it from some third-party websites, because it is difficult to guarantee that the JDK downloaded from a third-party website has not been modified.

Take the most used JDK8 as an example. Its download address is: https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html. If you want to download other versions, please visit: https://www.oracle.com/java/technologies/oracle-java-archive-downloads.html .

After entering the JDK8 download page, there are many minor versions, generally we can choose the latest version. The JDK of the same version number also has versions suitable for different operating systems, so when downloading, you must choose according to your own operating system type, and you can know which operating system it is suitable for based on the JDK file name. Take the Windows version most used by developers as an example. There are two types of Windows JDK, one is executable file (file name suffix is .exe), and the other is compressed package; personally recommend to use compressed package, because compressed package It's very convenient, just unzip it; the executable file needs to be installed after execution, not to mention the time-consuming installation, new scholars may also not know where the JDK is installed.

Install JDK

If you downloaded the JDK compressed package, you only need to unzip it to the installation directory you want; if the downloaded JDK is an executable file, double-click to install it, and you need to select the installation directory during the installation process. There is a need The point to note is that at the end of the installation, you will be prompted whether to install JRE. Personally recommend not to install JRE, because you can run Java programs with JDK. There is no need to install another JRE. After installing JRE, new scholars may be confused instead. As for the difference between JDK and JRE, I have the opportunity to publish an article later, so I won’t repeat it here.

Tip: Do not include Chinese characters in the directory path of the JDK installation. For earlier versions of the JDK, if there are Chinese characters in the installation directory path, there will be some inexplicable errors. Although the high version of JDK no longer has this problem, I still recommend not to install the directory path. Chinese characters are used in. In addition, it is best to install the JDK in a dedicated directory to facilitate the installation of other versions of JDK later. For example: C:\Java, Javathe directory contains the version with the JDK.

Configure JDK

When configuring the JDK, you only need to configure a few environment variables:

a. Open the environment variable configuration window, the steps are: right click on my computer -> properties -> advanced system settings -> environment variables, the configuration window is as follows: the
JDK installation and precautions
configuration window is divided into user environment variables and system environment variables. Effective for the current user, system environment variables are effective for all users. Generally, we can configure it in the user environment variable.

b. Configure JAVA_HOMEenvironment variables. This environment variable is used to specify where the root directory of the JDK is. For example:, C:\Java\jdk1.8.0_191this environment variable must be configured, because many Java software will determine the installation location of the JDK based on this environment variable.

c. Configure the classpathenvironment variable (no need to configure after JDK5). The environment variable is used to specify the Java class path, and the corresponding class file can be found; the variable name can be uppercase or lowercase, that is, case-insensitive. During configuration, the path generally comprises two classes, one is the current directory ( ., dot), and the other is the JDK lib, for example: .;C:\Java\jdk1.5.0-22\lib. You may have seen the rt.jar, dt.jar, tools.jarconfiguration classpath, this kind of configuration, no problem, just more convenient.

Since the libdirectory is located in the root directory of the JDK, we can classpathrefer JAVA_HOMEto it in the environment change , so the classpathenvironment variable is configured to .;%JAVA_HOME%\lib. The advantage of this is that when switching the JDK version, you only need to change it JAVA_HOME.

. D configuration Pathenvironment variables, in general, the environment variable already exists before you configure JDK, only need to under the root directory of JDK bindirectory to Paththe environment variable can be, such as: %JAVA_HOME%\bin. Configuring the purpose is to facilitate the implementation of environmental variables java, javacsuch as command, enter the command line directly java, javacwithout the need to enter the full path of the command, in other words, if you do not trouble free, willing to enter the full path in the command line, this environment variable is not Configuration is also possible.

Test JDK

Directly enter the javaccommands in the command line, and enter the corresponding command help information, then the installation is successful. After configuring the environment, javacyou must start a new command line before executing the command, because the new command line can read the environment variables just configured.

Linux install JDK

When installing the JDK on a Linux system, the steps are the same, but the method is different:

  1. Configure environment variables in /etc/profilefiles in Linux
  2. Use when referencing environment variables ${OTHER_VAR}, for example:${JAVA_HOME}
  3. The path uses PATHenvironment variables, and multiple paths :are separated by signs, for example:PATH=${JAVA_HOME}/bin:${PATH}
  4. After configuring the /etc/profilefile, execute the source /etc/profilecommand and use the environment variable just configured to take effect

-------------------------------- END -------------------------------

For more exciting articles in time, please pay attention to the public account "Java Essentials".

Guess you like

Origin blog.51cto.com/xtayfjpk/2657913