Lesson 2. Install JDK and Eclipse IDE | Learn Basic Java

Published on
Belongs to Category: Learn Basic Java|Posted by: Le Thanh Giang||4 min read
Facebook share iconLinkedIn share iconTwitter share iconPinterest share iconTumblr share icon
Lesson 2. Installing JDK and Eclipse IDE | Learn Basic Java

To start programming in Java, you need to install essential tools such as JDK (Java Development Kit) and an IDE (Integrated Development Environment) like Eclipse to assist with writing code, compiling, and running Java programs.

Installing JDK

JDK (Java Development Kit) is a complete set of tools for Java developers. When you install JDK, you will have all the necessary tools to develop and run Java applications, including:

  • javac compiler: Used to compile Java source code (.java) into bytecode (.class).
  • Java Runtime Environment (JRE): The environment that executes Java applications, including:
    • JVM (Java Virtual Machine): Converts bytecode into machine code and runs the Java application.
    • Java Standard Library: APIs needed to perform basic functions.
    • Other supporting tools: Configuration tools and the runtime environment for Java.

Steps to Install JDK:

  1. Download JDK:

  2. Install JDK:

    • After downloading the installer, run the .exe file (Windows) or the installer suitable for your operating system.
    • Follow the on-screen installation steps to install JDK in the default directory (or you can choose a different directory).
  3. Verify Installation:

    • Open Command Prompt (Windows) or Terminal (macOS/Linux), and type the command:
      java -version
      
    • If the system displays the JDK version, the installation was successful.
  4. (Optional) Set Up Environment Variables if Step 3 Fails: If you run the command java -version and do not get a result, the issue might be that the environment variable is not correctly configured. Follow these steps:

    • You need to set the JAVA_HOME environment variable so the system can recognize the JDK path.
      • For Windows:
        1. Search for "Environment Variables" in the search bar and select "Edit the system environment variables."
        2. In the System Properties window, click "Environment Variables."
        3. Under "System variables," click "New" and enter:
          • Variable name: JAVA_HOME
          • Variable value: The path to the JDK installation folder (e.g., C:\Program Files\Java\jdk-17)
        4. Next, find the Path variable under "System variables," and click "Edit." Add the path to the bin folder inside the JDK directory (e.g., C:\Program Files\Java\jdk-17\bin).
      • For macOS/Linux: Open the terminal and add the following lines to the ~/.bash_profile file (or ~/.zshrc if using zsh):
        export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
        export PATH=$JAVA_HOME/bin:$PATH
        
        Then run source ~/.bash_profile (or source ~/.zshrc) to apply the changes.

Installing Eclipse IDE

Eclipse is one of the most popular IDEs for Java, helping developers write code, compile, and debug Java applications. Key features of Eclipse include an integrated compiler, debugging support, and efficient project management.

Steps to Install Eclipse:

  1. Download Eclipse:

    • Visit the official Eclipse website at https://www.eclipse.org/downloads/.
    • Select the Eclipse IDE for Java Developers version and download the installer for your operating system.
  2. Install Eclipse:

    • After downloading the .exe (Windows) or .dmg (macOS) installer file, simply run the installer and follow the on-screen instructions.
    • Choose the installation directory and wait for the installation process to complete.
  3. Run Eclipse:

    • After installation, launch Eclipse IDE. Upon the first launch, Eclipse will ask you to select a workspace (the folder to store your projects).
    • After selecting the workspace folder, Eclipse will start up and be ready for you to begin Java programming.
  4. Configure Eclipse with JDK:

    • When Eclipse starts, you may need to specify the path to JDK if Eclipse does not automatically detect it.
      • Go to Window > Preferences.
      • Find Java > Installed JREs.
      • Click Add and select the path to the JDK installation folder.
      • Click OK to save the configuration.

Conclusion

After installing JDK and Eclipse, you will have all the necessary tools to program in Java. JDK provides all the essential tools to develop and run Java applications, and Eclipse is a great tool that helps you write code, compile, debug, and manage Java projects effectively.

Try creating your first Java project and run a "Hello World" program to ensure everything works correctly. Good luck on your journey to learning Java programming!

Next Lesson: Lesson 3. Classes in Java

Latest Posts

Related Posts

Newsletter border

Subscribe to Receive Updates from RiverLee