Java Development Environment Setup

  • Last updated Apr 25, 2024

To get started with Java development, the first step is setting up the Java environment on your operating system. Whether you're using Windows, Mac, or Ubuntu/Linux, this guide will walk you through the process, ensuring a smooth and hassle-free setup.

The JDK, short for Java Platform, Standard Edition Development Kit, is a development environment required for building applications using the Java programming language. It includes tools that are useful for writing, compiling, and testing programs written in the Java programming language and running on the Java platform.

What are the differences between OpenJDK and Oracle JDK?

Oracle JDK and OpenJDK are both Java Development Kits, comprising software and specifications. Starting from Java 11, Oracle JDK and OpenJDK have the same build, incorporating features like Flight Recorder and Mission Control. In essence, there are minimal to no code differences between Oracle JDK and OpenJDK, making them functionally very similar.

The main difference lies in their development and licensing. OpenJDK is an open-source project maintained by the Java community, with contributions from various organizations, including Oracle. On the other hand, Oracle JDK is a proprietary implementation of the Java SE platform provided by Oracle Corporation, and it is solely maintained by Oracle. Beginning with Java 11, Oracle introduced a new commercial license for Java. If you intend to use the official JDK in a commercial setting, you may need to purchase a license from Oracle.

Which JDK to choose?

When choosing between OpenJDK and Oracle JDK, performance is similar for Java SE compliant code. Consider factors like cost, Java support needs, and other preferences. Many experts recommend migrating to OpenJDK, especially for Linux-based stacks. Be cautious if moving from an older Oracle JDK version, as some internal APIs might differ. Given recent pricing changes by Oracle, exploring a switch to OpenJDK could be worthwhile.

Setting Up Java  Development Environment on Windows
  1. Visit the official OpenJDK distribution website.
  2. Download the latest version of JDK for Windows.
  3. Extract the ZIP archive contents to C:\Program Files\Java.
  4. Set the Java Home:
    1. Right-click on This PC.
    2. Choose Properties.
    3. Click on Advanced system settings.
    4. Click the Environment Variables button.
    5. In the System variables section, click New to add a new variable.
    6. Set the variable name to JAVA_HOME and the variable value to the path of your Java installation directory (e.g., C:\Program Files\Java\jdk-VERSION).
  5. Update the PATH Variable:
    1. In the same Environment Variables window, find the Path variable in the System variables section.
    2. Select Path and click Edit.
    3. Click New and add %JAVA_HOME%\bin to the list. This ensures that the system can find Java executables.
    4. Click OK to close the windows.
  6. Verify the Installation:
  7. Open a new Command Prompt window, type java -version, and press Enter. This should display information about the installed Java version. For example:

    java -version

    Similarly, type javac -version to verify that the Java Compiler is accessible. For example:

    javac -version
  8. Visit the official website of Eclipse, download Eclipse IDE for Enterprise Java and Web Developers for Windows, and proceed with the installation.
Setting Up Java Development Environment on Mac

To install and set up OpenJDK on macOS, you can use a package manager like Homebrew. Here are the steps:

  1. Open Terminal and run the following command to install Homebrew:
  2. /bin/bash -c "$(curl -fsSL"
  3. Use Homebrew to install OpenJDK. You can choose the version you want (e.g., 17, 18, 19, 20, 21) based on your requirements:
  4. brew install openjdk@17

    Replace 17 with the desired version number.

  5. Set up environment variables:
    1. After installation, you need to set the JAVA_HOME environment variable. Open your shell profile file (usually ~/.zshrc for Zsh or ~/.bash_profile for Bash) in a text editor. You can use the nano editor in the Terminal:
    2. nano ~/.zshrc
      nano ~/.bash_profile
    3. Add the following line at the end of the file:
    4. export JAVA_HOME=$(brew --prefix openjdk@17)
      export PATH=$JAVA_HOME/bin:$PATH

      Make sure to adjust the version number if you installed a different version.

    5. Next, save the changes and exit the text editor. To apply the changes, you can either restart your terminal or run the following command:
    6. source ~/.zshrc   # For Zsh
      # or
      source ~/.bash_profile   # For Bash
    7. Verify the version of installed Java by running the following commands:
    8. java -version

      The above command should display the information about the installed version of Java.

      javac -version

      This command should display information about the installed Java compiler version.

  6. Visit the official website of Eclipse, download Eclipse IDE for Enterprise Java and Web Developers for MacOs, and proceed with the installation.
Setting Up Java Development Environment on Ubuntu/Linux
  1. Open a terminal and update the package lists to make sure you have the latest information about available packages:
  2. sudo apt update
  3. Install OpenJDK using the following command. The version number may vary, so replace 17 with your desired version (e.g., 18, 19, 20, 21, etc.):
  4. sudo apt install openjdk-17-jdk

    This command installs the OpenJDK development kit (JDK), which includes the Java Runtime Environment (JRE) and other tools necessary for Java development.

  5. After the installation is complete, verify that Java is installed correctly using this command:
  6. java -version

    This should display the information about the installed version of Java.