Java Development Environment Setup
In this section, we will guide you through setting up a Java development environment.
- Installing Development Environment on Windows
- Installing Development Environment on Linux
- Installing Eclipse to Run Java
Installing Java on Windows System
Download JDK
First, we need to download the Java Development Kit (JDK). The download link is: https://www.oracle.com/java/technologies/downloads/. On the download page, select the version corresponding to your system. This guide uses the Windows 64-bit system as an example:
After downloading, follow the prompts to install the JDK. During the installation, both JDK and JRE will be installed.
During the JDK installation, you can customize the installation directory, for example, C:\Program Files (x86)\Java\jdk1.8.0_91.
Configure Environment Variables
- After installation, right-click "This PC," click "Properties," and select "Advanced system settings."
- Select the "Advanced" tab and click "Environment Variables."
You will see a screen like the following:
In "System Variables," set three attributes: JAVA_HOME, PATH, and CLASSPATH (case insensitive). If they already exist, click "Edit"; if not, click "New."
Note: If you are using JDK version 1.5 or higher, you do not need to set the CLASSPATH environment variable to compile and run Java programs.
The variable settings are as follows:
- Variable Name: JAVA_HOME
- Variable Value: C:\Program Files (x86)\Java\jdk1.8.0_91 // Configure according to your actual path
- Variable Name: CLASSPATH
- Variable Value: .;%JAVAHOME%\lib\dt.jar;%JAVAHOME%\lib\tools.jar; // Remember there is a "." at the beginning
- Variable Name: Path
- Variable Value: %JAVAHOME%\bin;%JAVAHOME%\jre\bin;
JAVA_HOME Setup
PATH Setup
Note: In Windows 10, the Path variable is displayed in separate lines. We need to add %JAVAHOME%\bin;%JAVAHOME%\jre\bin; separately, otherwise it will not be recognized:
%JAVA_HOME%\bin;
%JAVA_HOME%\jre\bin;
For more details, refer to: Configuring Java Environment Variables on Windows 10
CLASSPATH Setup
This is the Java environment configuration. After completing this setup, you can start Eclipse to write code, and it will automatically configure the Java environment.
Testing JDK Installation
- Go to "Start" -> "Run" and type "cmd."
- Enter the commands: java -version, java, javac. If the following information appears, the environment variable configuration is successful.
Environment Variable Setup on Linux, UNIX, Solaris, FreeBSD
The environment variable PATH should be set to point to the location where the Java binary files are installed. If you encounter difficulties, refer to the shell documentation.
For example, if you are using bash as your shell, you can add the following line to the end of your .bashrc file: export PATH=/path/to/java:$PATH
Popular Java Development Tools
As the saying goes, "A workman is known by his tools." We also need a good development tool when developing Java. There are many IDEs on the market. This article recommends the following Java development tools:
- Eclipse (Recommended): Another free and open-source Java IDE. Download link: http://www.eclipse.org/downloads/packages/ Select Eclipse IDE for Java Developers.
- JetBrains' IDEA: Many people are starting to use it now, with powerful features. Download link: https://www.jetbrains.com/idea/download/ -VSCode: VSCode (short for Visual Studio Code) is a free, cross-platform source code editor developed by Microsoft. Installation guide: https://www.tutorialpro.org/w3cnote/vscode-tutorial.html
-Netbeans: An open-source, free Java IDE, download link: http://www.netbeans.org/index.html
Running Your First Java Program with Eclipse
Video demonstration as follows:
HelloWorld.java file code:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Running Java Programs in Cloud Studio
>
Java is a cross-platform programming language. To run Java programs on your computer, you need to install JRE, and to develop Java programs, you need to install JDK. This might be complex for beginners and issues may arise during the installation and configuration process. For experienced developers, there might be times when they need to temporarily develop and debug code on a computer without a Java environment. Therefore, it is recommended to use the online cloud-based development tool Cloud Studio based on Tencent Cloud to quickly start your Java project.
Step 1: Visit the Tencent Cloud Developer Platform, and register/log in.
Step 2: Select the environment
"PHP + Python + Java"
from the runtime environment menu on the right.Step 3: Create a new Java directory in the code directory on the left for development.
Tips: From the terminal commands, you can see that Cloud Studio integrates the Ubuntu16.04 + Java1.8 development environment:
For any questions, refer to the help documentation.
Currently, CODING is hosting a contest for the most favorite Cloud Studio plugins. Visit the event website: https://studio.qcloud.coding.net/campaign/favorite-plugins/index for more information.