YouTip LogoYouTip

Java Environment Setup

In this chapter, we will introduce how to set up a Java development environment. * * * ## Installing Java on Windows Systems ### Downloading the JDK First, we need to download the Java Development Kit (JDK). The download link is: [https://www.oracle.com/java/technologies/downloads/](https://www.oracle.com/java/technologies/downloads/). On the download page, select the appropriate version for your system. This tutorial uses the Windows 64-bit system as an example: !(#) After downloading, follow the prompts to install the JDK. The JRE will also be installed alongside the JDK during this process; you can install them together. During the JDK installation, you can customize the installation directory and other information. For example, we choose the installation directory as **C:Program Files (x86)Javajdk1.8.0_91**. ### Configuring Environment Variables 1. After installation, right-click on "My Computer", click "Properties", and select "Advanced system settings"; !(#) 2. Select the "Advanced" tab and click "Environment Variables"; !(#) Then the following screen will appear: !(#) Set three properties in "System Variables": JAVA_HOME, PATH, and CLASSPATH (case doesn't matter). If they already exist, click "Edit"; if not, click "New". > **Note:** If you are using JDK version 1.5 or above, you do not need to set the CLASSPATH environment variable, and Java programs can still be compiled and run normally. The variable settings 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 the "." at the beginning * Variable name: **Path** * Variable value: **%JAVA_HOME%bin;%JAVA_HOME%jrebin;** ### Setting JAVA_HOME !(#) !(#) ### Setting PATH !(#) !(#) > **Note:** In Windows 10, the Path variable is displayed as separate entries. We need to add **%JAVA_HOME%bin;%JAVA_HOME%jrebin;** as separate entries; otherwise, it will not be recognized: > > %JAVA_HOME%bin;%JAVA_HOME%jrebin; > !(#) > > > For more details, please refer to: (#) ### Setting CLASSPATH !(#) This is the Java environment configuration. After the configuration is complete, you can launch Eclipse to write code, and it will automatically complete the Java environment configuration. ### Testing if the JDK is Installed Successfully 1. Go to "Start" -> "Run", type "cmd"; 2. Type the commands: **java -version**, **java**, **javac**. If the following information appears, the environment variable configuration was successful; !(#) * * * ## Environment Variable Setup for Linux, UNIX, Solaris, FreeBSD The PATH environment variable should be set to point to the location where the Java binary files are installed. If you have trouble setting it, please refer to your shell documentation. For example, assuming you use 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 craftsman must sharpen his tools to do his work well. Similarly, in the process of developing with the Java language, we also need a good development tool. There are many IDEs on the market today. This article recommends the following Java development tools: * **JetBrains** IDEA, which many people are starting to use now. It is very powerful. Download link: [https://www.jetbrains.com/idea/download/](https://www.jetbrains.com/idea/download/) !(#) * **VSCode:** VSCode (full name: Visual Studio Code) is a free, open-source, and cross-platform source code editor developed by Microsoft. Download link: [https://code.visualstudio.com/](https://code.visualstudio.com/) Installation tutorial: [ !(#) * **Netbeans:** An open-source and free Java IDE. Download link: [https://www.netbeans.org/index.html](https://www.netbeans.org/) !(#) * **Eclipse:** Another free and open-source Java IDE. Download link: [https://www.eclipse.org/downloads/packages/](https://www.eclipse.org/downloads/packages/) Choose **Eclipse IDE for Java Developers**: !(#) ### Creating Your First Java Application with IntelliJ IDEA * 1. Launch IntelliJ IDEA. * 2. Click "New Project" on the welcome screen. * 3. In the "New Project" wizard, select "Java" from the list on the left. * 4. Name the project (e.g., HelloWorld) and change the default location if needed. * 5. In this tutorial, we will not use a version control system, so please disable the "Create Git repository" option. * 6. Ensure that IntelliJ is selected as the build system. !(#) To develop Java applications in IntelliJ IDEA, you need the Java SDK (JDK). If the required JDK is already defined in IntelliJ IDEA, select it from the JDK list. If the JDK is installed on your computer but not defined in the IDE, select "Add JDK" and specify the path to the JDK home directory (e.g., /Library/Java/JavaVirtualMachines/jdk-20.0.1.jdk). !(#) To create a package and class, in the Project tool window, right-click the src folder, select New, and then select Java Class. In the Name field, enter com.example.helloworld.HelloWorld and click OK. IntelliJ IDEA will create the com.example.helloworld package and the HelloWorld class. (https://static.jyshare.com/video/jt-package-class.mp4) Start writing code: (https://static.jyshare.com/video/jt-main-method.mp4) Write code that outputs Hello World: (https://static.jyshare.com/video/jt-hello-world.mp4) Execute the code and output the result: (https://static.jyshare.com/video/jt-run-app.mp4) ### Running Your First Java Program with Eclipse The video demonstration is as follows: (https://static.jyshare.com/video/javadownload-20200329.mp4) The code for the HelloWorld.java file: public class HelloWorld{public static void main(String[]args){System.out.println("Hello World"); }}
← Java Basic SyntaxJava Intro β†’