preface

The first thing to learn Java programming is to set up the development environment, so as to start a happy programming learning journey. However, many new students often fail to build a good development environment because of various problems, resulting in their confidence frustrated, learning interest and passion is greatly reduced, and even give up learning Java programming completely! Although there is a lot of relevant information on the Internet, but the fish and the fish are mixed, opinions are not only unable to solve the problem, but also make the cute new confused.

In order to help new students get into the Java world, I have crafted this tutorial, which not only provides very detailed instructions, but also collects solutions to various common problems (which are constantly updated). Just take a few minutes to read the following and you will have a successful Java development environment!

Java Development Kit (JDK) : Java Development Kit (Java Development Kit), which provides various tools needed to develop and debug Java programs, Java programming essential. This tutorial uses the open source free JDK version, the OpenJDK, rather than the commercial version of the JDK provided by Oracle corporation (OracleJDK for short). I recommend that you use the OpenJDK. The differences between the two are covered in the FAQ.

After installing and configuring the JDK, you can use the notepad of the system to write Java code, and then call javac and Java commands in the command line to compile and run the code, without installing any other tools. However, this approach is inefficient and the programming experience is terrible. Simple programs may be able to cope, but if you develop large and complex projects, it will definitely make you doubt your life!

Work is good for its things will first benefit its tools, so we also need to install a more powerful integrated development tools, will develop required tools integrated in a software, convenient for us to use, is usually said IDE, this tutorial uses the world’s popular Eclipse software.

The little knowledge

IDE: Integrated Development Environment (IDE) is the software used to provide the program Development Environment. It generally includes code editor, compiler, debugger, graphical user interface and other tools, integrating the code writing, analysis, compilation, debugging and other Development functions.

Eclipse is a well-known cross-platform IDE, which is open source and free. It was originally developed in Java language. However, as it is an extensible framework platform, it can easily support other programming languages, such as C++ and Python, by installing different plug-ins. Many software developers use Eclipse as a framework to develop their own ides.

The system and software versions used in this tutorial are as follows:

  • 10 64 – bit Windows
  • Its – 15.0.1 _windows – x64
  • eclipse-jee-2020-09-R-win32-x86_64

PS: Different versions of the system or software operation method is basically the same, in order to save valuable time, I suggest you use the same version and this tutorial!

steps

1. Download JDK and Eclipse

The official website is in English, but also very easy to get lost, for the convenience of you, I have downloaded from the official website JDK and Eclipse installation package uploaded to baidu web disk, for you to directly download and use.

Link: pan.baidu.com/s/181xs-LGn…

Extraction code: 4ZwR

After downloading, you get two compressed files as follows:

  • Its – 15.0.1 _windows – x64_bin. Zip
  • eclipse-jee-2020-09-R-win32-x86_64.zip

2. Decompress the JDK and Eclipse

Create a Java folder in drive D and unzip the two packages obtained in the previous step into the folder. As shown below:

3. Configure JDK environment variables

3.1 Right click “This Computer” on the desktop, click the “Properties” menu, and click the “Advanced System Settings” menu on the left in the open window;

3.2 Click the “Environment Variables” button in the “System Properties” window;

3.3 In the Displayed “Environment Variables” window, click “New” in the “System Variables” column;

3.4 In the open “New System Variable” window, input the variable name and value as shown below, and then click the “OK” button below;

PS: The variable name is JAVA_HOME, case insensitive, and the value is the actual decompression path of the JDK.

3.5 In the “Environment Variables” window, double-click the “Path” variable in the “System Variables” column, and perform operations in the “Edit Environment Variables” window as shown in the following figure.

PS: The input Path is the complete Path of the bin folder in the decompressed JDK folder. After adding this Path to the system Path environment variable, you can directly use the name of the javac and Java programs in the bin folder in the command line, without specifying their specific paths.

The little knowledge

A command is an executable program. When a command is executed by entering the name of a command (no specific Path is specified), the system reads the value of the Path environment variable and searches all paths in sequence until the corresponding executable program is found. Then the system stops searching and runs the command. If all paths are searched and no corresponding executable is found, an error is reported.

3.6 Click the “OK” button at the bottom of the “Environment Variables” window to close the remaining Windows.

PS: Be sure to hit the “OK” button here, otherwise all the previous configuration of the environment variables will not work!

4. Test whether the JDK is deployed successfully

Press WIN + R to open the “Run” window. Enter CMD and press Enter to open the “Command Prompt” window. Enter javac -version and java-version in the displayed window and press Enter. If the version information shown in the following figure is displayed, JDK has been successfully deployed. If there is an error, please carefully check the previous steps, especially the configuration of environment variables, try several times will definitely succeed!

5. Start Eclipse

After successfully deploying the JDK, open the folder where Eclipse was unzipped (D:\Java\ Eclipse in this case) and double-click the eclipse.exe executable to start Eclipse directly. For later use, you can send the file to the desktop shortcut (the desktop shortcut can change its name arbitrarily).

6. Write the first simplest program

6.1 After Eclipse is started, the following window is displayed, prompting you to set the workspace. You can click “Browse… Button to modify or leave the default, then click the “Launch” button at the bottom;

The little knowledge

Workspace: a folder where Java projects are stored.

6.2 Wait for a moment to open the Eclipse main interface. You can directly close the Welcome interface.

6.3 Click the menu File –> New –> Java Project;

6.4 In the open window, enter the Project name and specify the path for storing the Project folder as shown in the following figure, keep the default Settings for other configuration items, and then click the “Next” button at the bottom;

PS: In principle, the project name can be specified arbitrarily. However, to facilitate development and maintenance, you are advised to name the project based on its functions. Each project has a corresponding folder, which is called the project folder. All source files, resource files, and configuration files in the project are stored in this folder for easy management.

6.5 Perform operations as shown in the following figure in the open window, and finally click “Finish” at the bottom to create a Java project;

6.6 Double-click the project name in the left sidebar to expand the project structure, then right click “SRC”, and click the menu New –> Class successively;

6.7 In the window that opens, enter the package name and class name as shown in the following figure. You can select automatic generation main method and click “Finish” at the bottom to create a new Java class.

PS: Package and Class knowledge and details are not covered here, and will be covered in more detail in subsequent tutorials. The main method (main) is the entry point to the execution of a Java program. After a Java program starts, it automatically starts from the first line of code in the main method, and then returns from the main method, the entire program ends.

6.8 Enter a value in the main methodSystem.out.println(" Hello, China!" );After this line of code, press Ctrl + S to save, and then click the green triangle button in the upper toolbar to compile and run the program code. If there are no errors, you can see the code running in the Console window below.

PS: The function of the code entered here is to display “Hello China!” in the Console window. This line of text.

Q&A

1. If the operation fails or other problems occur, what should I do?

Welcome to post your problems in the comments section below, AND I will help you analyze and solve them. You can also send me a private message.

2. What is the difference between OpenJDK and OracleJDK?

From the perspective of cost, OracleJDK will implement commercial charging policy from April 16, 2019. When you use OracleJDK 8U211 or above to develop software for commercial use, you must first pay Oracle to obtain the license, otherwise you may face huge legal risks. OpenJDK is completely open source and free to use.

From a technical point of view, the OracleJDK is built on top of OpenJDK, and the two are not very different, although the OracleJDK is a bit better in terms of performance optimization and stability. More and more enterprises are using OpenJDK in their actual production environments. We are using OpenJDK in our Web and mobile application background. For learners, there is virtually no difference. In addition, Oracle is not very friendly to the open source community and individual developers, while the OpenJDK community is very active and has a growing number of loyal users.

To conclude, I recommend using OpenJDK.

3. Why not use OracleJDK 8?

Many individuals and tutorials are still using the older version of OracleJDK 8 and are refusing to use newer versions, largely because the newer version is no longer free (OracleJDK 8U202 was the last free version). The new JDK will not only bring some new Java syntax features, but also Bug fixes, performance and stability improvements that you wouldn’t get if you stuck with older versions. If you want to use a newer version of the JDK but don’t want to pay for commercial use, the best solution is to use a newer version of OpenJDK.

4. The javac or Java command cannot be executed, and the following error occurs:

JDK environment variables are not configured successfully. Specifically, the value of the Path environment variable does not contain the correct Path of the bin folder in the JDK installation (decompression) folder.

5. Why is the CLASSPATH environment variable not configured?

After JDK version 5 (JDK 15 is used for this tutorial), you no longer need to configure the CLASSPATH environment variable. Of course, there’s no problem if you have to.

6. The javac or Java command is executed successfully, but the version information is not 15.0.1

You are advised to remove JDK paths from all JAVA_HOME, CLASSPATH, and Path variables. Then reconfigure the environment variables as described in the previous steps.

7. Eclipse fails to start, and an error pops up as follows:

JDK environment variables are not configured successfully. Check and modify them according to the preceding steps to ensure that Eclipse can run properly after JDK deployment is successful.

8. Eclipse fails to start, and an error pops up as follows:

The JDK version in effect on the system is JDK 8, while Eclipse currently requires JDK 11 or higher to start properly. After you have completely removed the previously installed lower JDK (removing the JDK folder and associated environment variables), redeploy the JDK provided in this tutorial, and then run Eclipse.