Some concepts about JDK and JDK installation configuration (applicable to Linux/Windows)

Preface

The configuration of Java development environment is actually not complicated. It is also a process of downloading and installing-environment variables-terminal test version. The problem is that Java has a lot of concepts that are difficult to distinguish, such as OpenJDK, OracleJDk, JavaSE, JavsEE, JavaME, etc. In fact, they are not complicated to understand.

reference

1.JDK has so many names? What's the difference?

The origin of the matter has to start with the history of Java development. To put it simply, Java used to be managed by Sun. Later, Oracle took over Java and continued to update Java. The Java released by Oracle was called OracleJDK. Later, Oracle open sourced Java and established the OpenJDK project. This The project later became OpenJDK. In other words OracleJDK和OpenJDK是一家公司的, they reach the same goal by different paths , and at least at the code level their differences are minimal. The big difference is in the license:

OpenJDK is released under the license GPL v2.
OracleJDK is licensed under the Oracle Binary Code License.

OpenJDK project home pageOpenJDK
download
pageOracleJDK home page

Later, more companies participated in the maintenance of OpenJDK, and major Internet companies also released JDK with their own commercial standards, as follows:

Build LTS permissive license TCK test Unmodified build from upstream Provide commercial support
AdoptOpenJDK Yes Yes No Optional Optional (IBM)
Alibaba Dragonwell Yes Yes Yes No No
Amazon Correct Yes Yes Yes No Optional (on AWS)
Zulu Blue Yes Yes Yes No Optional
BellSoft Liberica JDK Yes Yes Yes No Optional
Huawei bisheng JDK Yes Yes Yes No No
IBM Java SDK Yes No Yes No Yes
Microsoft Build of OpenJDK Yes Yes Yes No No (beta)
ojdkbuild Yes Yes No Yes No
OpenLogic OpenJDK Yes Yes Yes No Optional
Oracle GraalVM Community Edition No Yes Yes No No
Oracle GraalVM Enterprise Edition Yes No Yes No Yes
Oracle Java SE Yes No Yes No Yes
Oracle OpenJDK No Yes Yes Yes No
Red Hat build of OpenJDK Yes Yes Yes No Yes
Tencent Kona Yes Yes Yes No No
SAP SapMachine Yes Yes Yes No Optional (for SAP products)

LTS: Abbreviation for "Long Term Support", that is, long-term support version
TCK: a test provided by the OpenJDK project, which is actually not very important

All in all, no matter what JDK, it can be said to be derived from the OpenJDK project to some extent, but they have slight differences in protocols, interfaces, etc.

2. What are JavaEE, JavaSE and JavaME?

JavaSE: The abbreviation of Java Standard Edition, commonly known as JDK.
JavaEE: The abbreviation of Java Platform Enterprise Edition, which is the Java Platform Enterprise Edition. A set of interfaces and standards are added to JavaSE, which is mostly used for enterprise-level development, including web development. .
JavaME: Java Micro Edition, which is a micro version of Java, is a shortened version of JavaSE. It is mostly used for the development of mobile devices such as mobile phones and set-top boxes.

3. How to choose JDK?

It is not recommended to use the original OpenJDK directly.

It’s not that the more Yes in the above table, the better.

Personally, I recommend those that have installation packages corresponding to the operating system , such as .deb packages for Debian systems, etc. The main reason is that using installation packages is convenient for uninstalling configurations, etc., and some installation packages will set environment variables for you (out of the box!) , Secondly, some Java applications detect the location of Java by detecting the registry. Using the installation package will be extremely convenient.

In the end, the choice is based on personal needs, such as architecture and required JDK version. Alibaba's DragonWell only has JDK8 and JDK11.
I personally recommend BellSoft's JDK (Full version), AdoptiumJDK, and AmazonJDK. The ranking indicates the degree of recommendation. Their common features are: installation packages provided, multiple JDK versions, and fast domestic downloads.

4.JDK installation and configuration

Take BellSoftJDK as an example

Windows

Download the msi installation package from the official website and install it.

Then configure the environment (BellSoft's JDK will directly add environment variables for you. If you don't mind it, you can leave it alone. I choose to delete it directly here)
Insert image description here

Create a new one in the system variable JAVA_HOME, all capital letters. Some software obtains the JDK through the JAVA_HOME environment variable by default. If you have multiple JDKs, you can configure them like me, so that you can switch the global JDK with only a simple change.

Insert image description here
Insert image description here
Insert image description here
Insert image description here

Remember to declare the following in Path. This Path will not need to be touched in the future.
Insert image description here
After directly operating JAVA_HOME, you can still check it with cmd:
Insert image description here

Linux

If there is an installation package, install it directly. If not, find a place to unzip it. Anyway, you will get a folder in the end.

If you are installing using an installation package, you can directly skip the step of registering update-alter. If you are installing via zip, you need to manually register the update-alter corresponding to jdk. Reference article

update-alternatives --install /usr/bin/java java /example/jdk-1.8/bin/java 100 ##最后面的数字大小表示优先级
update-alternatives --install /usr/bin/java java /example/jdk-11/bin/java 200 ##倒数第二个参数是JDK目录
update-alternatives --install /usr/bin/java java /example/jdk-17/bin/java 300 ##其它的不用动

update-alternatives --install /usr/bin/javac javac /example/jdk-1.8/bin/javac 100
update-alternatives --install /usr/bin/java javac /example/jdk-11/bin/javac 200
update-alternatives --install /usr/bin/javac javac /example/jdk-17/bin/javac 300

In any case, you can use update-alternatives --config javacand update-alternatives --config javato quickly switch compilers:
Insert image description hereyou can also add the following environment variables later, which are available in ~/.zshrcand ~/.bashrc. It is not recommended to configure them globally directly.
It should be noted that this environment variable will not affect update-alternatives --config javacthe options. If you choose jdk8, the compiler output will still be jdk8, and it will not change because it is jdk17's java_home.
Please add image descriptionNote that this must be present/

If you are more skillful, you can also use the alias abbreviation in .zshrc to quickly switch between java and javac versions.
Insert image description here

alias changejdk8="echo 2 | sudo update-alternatives --config java && echo 2 | sudo update-alternatives --config javac && java -version && javac -version"

Off topic: VSCode configuration

VSCode's Java plug-in sometimes does not use JDK. In this case, you need to configure it manually:

Linux and Windows are the same

Insert image description here
If there are multiple JDKs, you can configure them like this. The one marked default uses the JDK by default.

Insert image description here

Guess you like

Origin blog.csdn.net/m0_74075298/article/details/132562410