DEV Community

Cover image for How to Set Up Your Environment to Start Java Development
Ricardo Caselati
Ricardo Caselati

Posted on

How to Set Up Your Environment to Start Java Development

If you're here, you're likely looking to learn how to set up your environment for Java development. The first step is to install the SDK (Software Development Kit), a set of tools and libraries provided by hardware and software vendors.

For Java, we use the JDK (Java Development Kit). The JDK is a collection of utilities that enable you to build applications for the Java platform. It includes a compiler, libraries, and essential tools. Keep in mind that Java is not just a programming language but also a platform. One of its key advantages is platform independence, meaning your programs can run on any compatible system.

Now that you know what we’ll be installing and its purpose, let’s get started!

Step 1: Update System Packages

Before anything else, ensure your system packages are up to date. Run the following command in your terminal:

sudo apt-get update && sudo apt-get upgrade
Enter fullscreen mode Exit fullscreen mode

Step 2: Install OpenJDK 17

The OpenJDK is a free, open-source implementation of Java. To install it, use this command:

sudo apt install openjdk-17-jdk
Enter fullscreen mode Exit fullscreen mode

Step 3: Check Installed Versions

If you have multiple Java versions installed, you’ll need to set one as the default. To list all installed versions, run:

sudo update-java-alternatives --list
Enter fullscreen mode Exit fullscreen mode

The output will look something like this:

java-1.17.0-openjdk-amd64      1711       /usr/lib/jvm/java-1.17.0-openjdk-amd64
Enter fullscreen mode Exit fullscreen mode

If only one version is listed (a single line), you can skip the next step. Otherwise, you’ll need to set OpenJDK 17 as the default.

Step 4: Set the Default Version

To configure OpenJDK 17 as the default version, use the command below, replacing the name with the path shown in your output:

sudo update-java-alternatives --set java-1.17.0-openjdk-amd64
Enter fullscreen mode Exit fullscreen mode

Step 5: Verify the Installation

Finally, check if everything is working correctly. To verify the installed Java version, run:

java -version
Enter fullscreen mode Exit fullscreen mode

You should see an output similar to this:

openjdk version "17.0.8.1" 2023-08-24  
OpenJDK Runtime Environment (build 17.0.8.1+1-Ubuntu-0ubuntu122.04)  
OpenJDK 64-Bit Server VM (build 17.0.8.1+1-Ubuntu-0ubuntu122.04, mixed mode, sharing)
Enter fullscreen mode Exit fullscreen mode

Also, confirm the compiler version, which should match the runtime version:

javac -version
Enter fullscreen mode Exit fullscreen mode

You're now ready to start developing in Java! In tomorrow's post, I'll guide you step by step on how to install IntelliJ IDEA, one of the most popular Integrated Development Environments (IDEs) for Java development. See you then!

Top comments (0)