In this chapter, we will introduce how to set up a Java development environment and how to configure environment variables under different systems.
This site provides java online running tools: https://www.w3cschool.cn/tryrun/runcode?lang=java-openjdk. However, due to insufficient permissions in the online environment, most codes cannot be run directly online, so we have to set up a local The operating environment is very important! ! !
First we need to download the java development tool kit JDK, download address: https://www.oracle.com/java/technologies/downloads/#java11-windows
Click the download button below:
On the download page, you need to choose to accept the license and select the corresponding version according to your system. This article takes the Window 64-bit system as an example:
After downloading, install the JDK according to the prompts. When installing the JDK, the JRE will also be installed. Just install it together.
Install JDK. During the installation process, you can customize the installation directory and other information. For example, we choose the installation directory as C:Program Files (x86)Javajdk11.0.1.
1. Right-click "My Computer" → "Properties" → "Advanced System Settings" → "Advanced" → "Environment Variables";
2. Select the "Advanced" tab and click "Environment Variables";
3. Create a new "JAVA_HOME" system variable (click the "New" button under "System Variables", fill in the variable name and value, and click "OK")
4. As above, create a new "CLASSPATH" system variable with the value “.;%JAVA_HOME%lib;%JAVA_HOME%libdt.jar;%JAVA_HOME%libtools.jar;”
. (All content within quotation marks, please note that the first point is a dot, not a comma)
5. Double-click the "Path" variable under "System Variables" to edit it. (At this time, you can see that JAVA_HOME already exists in the system variable), (some computers' "Path" is also written as "PATH")
This is the Java environment configuration. After the configuration is completed, you can start Eclipse to write code, and it will automatically complete the Java environment configuration.
Set 3 properties in "System Variables", JAVA_HOME, PATH, CLASSPATH (case does not matter). If it already exists, click "Edit", if it does not exist, click "New".
The variable setting parameters are as follows:
Variable name: JAVA_HOME
Variable value: C:Program Files (x86)Javajdk1.8.0_91 // Configure according to your actual path
Variable name: CLASSPATH
Variable value: .;%JAVA_HOME%libdt.jar;%JAVA_HOME%libtools.jar; //Remember there is a "." in front of it.
Variable name: Path
Variable value: %JAVA_HOME%bin;%JAVA_HOME%jrebin;
Note: If you use JDK version 1.5 or above, you can compile and run Java programs normally without setting the CLASSPATH environment variable.
1. Press the "win" and "R" keys on the keyboard at the same time to open the run, and enter "cmd" to confirm opening the console.
2. Type the commands: java -version , java , and javac. If the following information appears, the environment variables are configured successfully;
The environment variable PATH should be set to point to the location where the Java binaries are installed. If you have trouble setting up, please refer to the shell documentation.
For example, assuming you are using bash as your shell, you can add the following to the end of your .bashrc file: export PATH=/path/to/java:$PATH
As the saying goes, if you want to do your job well, you must first sharpen your tools. We also need a good development tool in the process of developing Java language. There are many IDEs on the market. This article recommends the following Java development tools for everyone:
Eclipse: Another free and open source java IDE, download address: https://www.eclipse.org/eclipseide/
Choose Eclipse IDE for Java Developers :
IntelliJ IDEA (recommended): An easy-to-use Java IDE. The professional version is powerful but requires payment. The open source version has enough basic functions to give you a better code development experience.
Download address: https://www.jetbrains.com/zh-cn/idea/
Notepad++: Notepad++ is a free code editor under the Microsoft windows environment. Download address: http://notepad-plus-plus.org/
In addition, there are many excellent code editors, such as vscode, sublime, vim, etc., which I won’t introduce too much here.
HelloWorld.java file code:
public class HelloWorld {public static void main(String []args) { System.out.println("Hello World");}}