preface

C: Did the previous introduction give you a sense of the Java language? After knowing each other, you may be anxious to get started programming, right? But like if you want to go swimming, you have to find a pool, right? So I have patience first, listen to the teacher said, before the formal development of a Java program, we should first in the computer, prepare the corresponding development environment, Java language development environment is JDK/JRE.

This is the first step of the long march, build a good Java basic development environment is Java developers must master skills, so The teacher suggests you, collect this tutorial, JDK installation several times, it is not rogue software, does not affect (uninstall does not remain, reinstall such as new).

A series of reading

Zha teacher said: although zha teacher heart you are the best, but if you did not read the last article, or suggested to open a quick string, in order to prevent the following content can not maintain continuity.

  • The Java syntax overview | Java”
  • The Java syntax | development environment set up”
  • The Java syntax | first Java program”

JDK and JRE concepts

First let’s introduce the concept of the JDK/JRE we will install.

The full name of JDK is Java Development Kit, that is, Java Development Kit, is provided by Sun Company for the Development of Java application Development package, it provides a variety of tools and resources required to compile and run Java programs. Including Java compiler, Java runtime environment (JRE), and common Java class libraries, etc.

JRE is a Java Runtime Environment. It is a prerequisite for running Java programs. If you only run Java programs, you can install JRE instead of JDK.

The teacher said: in the industry, are generally directly installedJDKBecause theJDKThere’s a built-inJRESo do we.

The choice of the JDK

Whose house do you choose?

With JDK concepts behind us, let’s take a look at the current state of the JDK. Sun developed the Java language at the beginning. As a development kit of the Java language, JDK was divided into two branches in the development of Sun. [Extended reading: Java finally open Source, under GPLv2 License]

  • Open JDKOpen source (the source code is made Public). The open source version is issued under the General Public License (GPL V2) protocol
  • Sun JDK, distributed using the Java Research License (JRL).

The GPL, known as the “virus” license in the open source license, must be open source as long as it is based on GPL open source code.

The JRL protocol, which is Sun’s own protocol, basically means that Sun discloses the code, but it owns the code itself, as you can see.

However, this protocol doesn’t affect our use of the JDK. It affects individuals and companies who want to change the JDK or redevelop it based on JDK code. We don’t touch the JDK code.

In fact, there is a large part of the same code in the development of the two branch versions, but the Open JDK is not as complete as the Sun JDK is certain (lack of some feature APIS), and part of the code can not be licensed to the Open JDK due to property rights and other reasons, so it is replaced in the Open JDK with code without property rights problems.

In order to avoid copyright problems, many large companies are using JDK versions based on Open JDK development or independent development, such as Amazon’s Corretto, Alibaba’s Dragonwell, Huawei’s Bi Sheng, Tencent’s Kona, etc. (our domestic Open source JDK blowout this year).

As we all know, Sun was acquired by Oracle in 2009, so Oracle owns the Java business and copyright. Oracle is responsible for the subsequent JDK updates, of course, but Oracle has a reputation in the industry for being expensive and expensive for everything. (In fact, the essence of a business is to make money, and Sun did not make much money before it disappeared. Oracle can be blamed for continuing to do this).

Between 2009 and 2019, Oracle didn’t make any major moves to charge fees, but that changed a bit on January 1, 2019. Oracle has announced that starting January 1, 2019, subsequent updates to Oracle JDK 8 will require a fee. The 8U211 and 8U212 updates to Oracle JDK 8 begin to change the license agreement from BCL to OTN, which means you can no longer use these versions in production.

The Oracle Binary Code License Agreement (BCL) allows you to use the JDK, but not modify it (similar to JRL), for both personal and commercial use, but for some commercial features in the JDK, you need to pay for them.

OTN protocol, also known as Oracle Technology Network License Agreement, is currently used in the newly released JDK. It can be used privately, but commercial use requires payment. [1]

As the fear was finally realized, many companies began to move JDK versions and consider their future options.

Below is the result of Jrebel’s survey of JDK choice in the Java Ecology Report in early 2020 (similar in China, fYI). According to the results, Oracle JDK(Sun JDK) and Oracle OpenJDK (Sun OpenJDK) still occupy a relatively large market position, but the share of AdoptOpenJDK is also rapidly increasing.

We are now learning to choose to use the Oracle JDK, the company depends on the architect or leader of the company. [Read on to learn more about JDK distributions]

Which version to choose?

Updates to the corresponding Open JDK for each version are not indefinite, but have a support period. Oracle JDK 8 is available as a personal and commercial version. These things are actually quite a headache, but we have no problem learning to use Oracle JDK, when entering the company, “when in Rome”.

Once the distribution is selected, what version do we use? Here’s Jrebel’s report, and it’s clear that JDK 8 is the most widely used. As of today, the JDK has been almost released to JDK 16, but the company is looking for stability, so there are not many updates or fixes, and generally the upgrade is very slow, you think about the path of Windows 7 to Windows 10 users to upgrade. In addition, JDK 9 and JDK 10 are not used because they are interim releases, similar to Windows8, and are not long-term support (maintenance) releases.

Download the JDK

Since we chose Oracle JDK 8, go to the Oracle website to download it.

1. Open the link below, or search for JDK on Baidu and find a page similar to the one below.

  • The international website

  • China’s official website

2. Scroll down to the bottom of the page to find Java Archive and click on the JDK Archive page.

As you can see, Java SE 8 is split into two links, 8U211 and after (charged) and 8U202 and before (free).

3. Click Java SE 8(8U2020 and Earlier) to go to the download page and select the platform version you want. Most of you should be using Windows 64-bit, so just choose the version indicated by the arrow below.

Remember to check the prostitution agreement.

Oracle now requires you to log in first to download the JDK. If you don’t have an account, register it yourself. The Internet is so slow! We can only bear!

4. Finally, the download is ready. It is too slow to check the hot network opened at teacher’s home.

The JDK installation

Download good, began to install JDK, and install QQ and other software, and it is not rogue software, not silent to you download a “family bucket”.

1. Double-click the installation package to start JDK installation, and click Next.

2. Click Change to change the JDK installation location.

We’ll create a new develop folder on any disk you choose and use it to install all your development programs later. Teacher Zha presented the develop folder on drive D.

In the dialog box that appears to change the installation directory, just change the drive letter D: and the folder develop, the subfolder Java\jdk1.8.0_xxx\ does not need to change, and then click OK. If the folder does not exist, it will be created automatically during installation.

Teacher cha said: installation path do not appear space, Chinese, special symbols and so on!

At this time the program will install the location has been changed, click next to start the installation.

Bonus: What exactly did we install when we installed the JDK?

When we selected the first development tool, we were prompted on the right, which is the JDK installed. It is the most important, even we can say that it is only necessary to have it.

The hint on the right is when we select the second source code, which is the Java 8 source code, because Java is open source.

When I selected the third public JRE, I was prompted on the right, which was a separate JRE that we didn’t need to install. Generally, though, we chose to install it so that in the future, if some Java programs want to run on their own, they will have to have a JRE attached to them.

For example, below is a Java program for signature verification provided by Alipay official when it supports third-party payment. The.jar extension is a Java program, but to run it you must rely on a separate JRE at the top, which you just saw on the installation selection screen. (Alipay official download down this tool, will give you with this JRE)

4. Wait for installation. This step is just installing the JDK.

After installing the JDK, a dialog box will pop up indicating that the JDK version is not affected by the charge. Click OK.

5. Since we did not abandon the standalone JRE installation, we will now install it and change the installation path ourselves. It’s best to do something like my example below and click Next.

Waiting for installation.

Click close to complete the installation.

No ICONS will appear on your desktop after installation. Don’t be surprised. JDK is a development environment, not a software like QQ.

The JDK installation directory is as follows.

Zha: The reason why WE said that we can not install the independent JRE, because JDK itself has a JRE, why JDK has a JRE? We will not discuss JDK built-in Java programs, just say we use JDK development Java programs, developed well also need to test run ah, so naturally need this JRE.

The installation directory of the independent JRE is as follows.

After the installation, we want to test whether the JDK is successfully installed. We can run the java.exe program in the bin directory of the JDK installation directory. If you can’t see.exe, turn on your computer’s extension display yourself.

In Windows, we’re used to double-clicking to run programs, but when we double click on java.exe, a black window pops up and flashes by. This is because of this program, they need to run in a special system, such as our DOS system, the following and Cha teacher to learn the basic DOS use it.

DOS system

What is DOS?

So what is DOS? Its full name is Disk Operating System. To put it simply, have you ever seen a movie where hackers are flying through a black window on a computer? The so-called black window is either DOS or Linux.

In fact, DOS is the early mainstream computer operating system, and then Windows and other main visual system appeared, just let the computer gradually get rid of professional concept, become “civilian”, into thousands of families. The reason for the specialization was that it was “too difficult” for non-specialists to memorize commands and get used to them because the system needed to be used by computers using commands rather than clicking around with a mouse.

Enter the DOS system

Anywhere in the Windows system, you can press the Windows key + R key, enter CMD and press Enter to pop up the DOS command line in the run window in the lower left corner.

Alternatively, you can open it as an administrator by searching CMD directly from the Start menu and right-clicking.

The DOS command line is displayed. Require an administrator id in the upper left (if you don’t have this id, you don’t have permission to create files, and some commands don’t even exist). If you’re running Windows 10, you probably won’t, because Windows 10 has more strict permissions, so you can use the second method above to access the DOS command line.

Enter the DOS command line, first understand the composition, the former part is your current path in the DOS system (current directory/folder, directory is the meaning of folder, will not explain later), the latter part is the location where you can enter the command.

The top path is equivalent to entering the following location in Windows.

Common DOS commands

Check the list

In the figure above, if we enter a path in Windows system, we can see all files and folders in the current path intuitively. So how do you do this in DOS?

Enter the dir command to list the files and folders in the current location, as shown in the following figure.

Switch directory

So if you don’t want to stay in the default path, you want to switch to another location.

  • To switch the directory of the same disk, use the CD directory path. (This path must exist, or the switch cannot pass)

    For example: I want to switch to the Documents directory in the current directory.

  • To switch directories of different disks, press drive letter: to switch disks, and then switch to CD directory path (note the space after CD) to the corresponding location.

    For example: I want to switch to the JDK installation directory.

    Teacher Zha said: if the path is long, when entering, you can also use Tab key to complete the content. For example, after entering De, you can press Tab to complete it quickly. Because DOS will automatically identify the name of the content under the directory, if you can match it, you can quickly complete, of course, if there are multiple De content, then try to enter more letters and then press Tab, so that more accurate.

There are also special path switches, such as going back to the previous directory. In Windows, a mouse click on the back key is all it takes. In DOS, you can use the CD.. Command to switch. . And. Are two hidden folders that exist under each directory, one representing the previous directory and one representing the current directory.

Also, if the disk is deep, you can enter CD/to quickly return to the root directory of the disk.

To run the program

In Windows, if you want to run a program, you double-click the program shortcut or the program startup file. In DOS, if we want to run a program, we just type the path to the program’s startup file and press Enter.

For example, if I want to run the pin program and I know its startup address, I can use the Tab prompt to quickly enter the address. The “” in the figure below is automatically generated by Tab. In DOS, in order to prevent the influence of space, you can add “” to wrap, indicating a whole.

This path is too long. If you need to use it again in DOS without closing the DOS window, you are advised to press ↑ or ↓ to view the history command.

Test whether the JDK is installed successfully

OK, master DOS basic use, this time we run through it under java.exe, input java.exe path is too long, we can steal a little lazy.

Find java.exe on Windows, then enter CMD in the address bar, and press Enter to quickly enter the program location.

Then you can run java.exe, followed by a -version to check the JDK version, if the following information is displayed, it indicates that the JDK installation is completely normal.

DOS can omit suffixes such as exe

The environment variable

An overview of the

C: After the content is done, in fact, our Java development environment has been built, we will always use the java.exe program after the development of Java. But now use or very troublesome, each time to find the program in DOS or input program path to run, there is no way to use Java. Exe in DOS any directory?

Take a look at Baidu Encyclopedia to learn about environment variables. Environment variables are parameters or key values stored in the operating system. Every program running in the operating system can obtain these stored contents. (We’ll get a better idea of what variables are for later, so check back later.)

Find environment variable Settings

Search for environment variables in the Start menu and click Edit System Environment Variables to open the system properties dialog box.

In the advanced TAB, clicking on environment variables takes you to the modify environment variables dialog box.

Path environment variable

The path environment variable is used to store the path list, which stores a path. When we input the name of the program in the DOS command line directly then press enter, then DOS will search the document in the current directory, if find the run, if can’t find the file, then according to the path environment variable set the path to the list, the order detailedly search the directory have the program, so also can run.

This is what we need now, to effectively solve the problem of running java.exe in the troublesome input path, etc., once and for all. Some students also saved some of their game startup programs in the PATH environment variable.

Configuration JAVA_HOME

Next, store the java.exe program directory into the PATH environment variable.

1. Click “Create” under System Variables. In the “Create” window, set the value of the variable to the JDK installation path (one level above the bin directory), and set the name of the variable to JAVA_HOME (the name is called because Maven, Tomcat and other development programs will use this environment variable in the future). Therefore, the name cannot be changed.

2. The environment variables stored above are incomplete and have not been added to the PATH environment variable. So we need to do a little more work in the PATH environment variable.

Click the path environment variable in the system variable, and then click Edit to remove a directory configuration that Oracle generates by default.

Click Add to add a variable named %JAVA_HOME%\bin. %JAVA_HOME% refers to the value of the JAVA_HOME environment variable. This variable is equivalent to adding D:\Develop\Java\jdk1.8.0_202\bin to your path.

Win7系统 path environment variables are all together, not like Win10 such a bar is very clear. Add a new one: %JAVA_HOME%\bin; (Always end this in English; To separate other environment variables! .

In addition, when we configure the Java installation path, we need to pay special attention not to delete the path configuration of some previous systems, and do not write wrong. (Do not enter directly when blue is selected, it will all be replaced!!) Otherwise, many system commands would not be easy and pleasant to use in DOS.

The test results

After the PATH environment variable is configured, close all DOS Windows. After re-opening DOS, type java-version, we see the same effect as before, and we do not need to type java.exe in the long path!

reference

[1] Dull melon eggs. Oracle how to charge for the JDK [EB/OL]. Zhuanlan.zhihu.com/p/64731331. 2019-06-18

Afterword.

So much for the INSTALLATION of the JDK. Supplement some basic content, more miscellaneous feeling, but the actual sequence of learning process, take a good look at this article outline! Practice each step! Come on! If you have any questions, please contact Teacher Cha by email or subscription number.

Teacher Zha said: For the learning of technology, teacher Zha has always followed the following steps: With a simple demo to let it run first, and then learn it the most commonly used API and configuration can let yourself up, finally, on the basis of proficiency in the spare time reading the source to try to make myself to be able to see clearly its running mechanism, part of the cause of the problem, at the same time, draw lessons from these technology to enhance your own code level.

So in the teacher’s article, the early basic are small white, only interspersed with a very small amount of source research. Of course, such as the small white update, you still like, the late will not regularly dedicated to part of the technology of the source code analysis.