Setting Up Java Development Environment

Setting up a computer for a Java environment can seem intimidating at first, but with a little guidance and some basic knowledge, it’s actually a fairly straightforward process. Whether you’re a beginner looking to start learning Java or an experienced developer looking to set up a new machine, this tutorial will help you get everything up and running smoothly.

Download Java Development Kit (JDK)

The JDK is a software development kit that contains the tools you’ll need to create, run, and debug Java programs. You can download the latest version of the JDK from the Oracle website (https://www.oracle.com/java/technologies/javase-downloads.html). Make sure to select the appropriate version for your operating system (Windows, Mac, or Linux).

Download Integrated Development Environment (IDE)

An IDE is a software application that provides a convenient environment for writing and debugging code. There are many different IDEs available for Java, but some of the most popular options include Eclipse, IntelliJ, and NetBeans. You can download any of these IDEs for free from their respective websites.

Once you have the JDK and an IDE installed, you’ll need to configure your computer to recognize the Java commands.

Setting up an environment in Windows machine

  1. Open the Start menu and search for Environment Variables.
  2. Click on Edit the system environment variables and then click the Environment Variables button.
  3. Under the System Variables section, scroll down and find the Path variable.
  4. Click on Edit and then click the New button.
  5. Add the path to the JDK bin folder (e.g., C:\Program Files\Java\jdk1.8.0_241\bin).
  6. Click OK to save the changes.

Setting up an environment in a Linux Ubuntu machine

To set the Java home path permanently in Ubuntu, you need to follow the steps given below:

  1. First, you need to find the location of your Java installation by running the following command in the terminal:
sudo update-alternatives --config java

This will display a list of all installed Java versions along with their paths. In my system I got the following output:

There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-1.8.0-amazon-corretto/jre/bin/java
Nothing to configure.

You may see a similar kind of output.

  1. Note down the path of the Java version you want to use as the default.
  2. Next, open the /etc/environment file using a text editor with root privileges, for example:
sudo vim /etc/environment

I prefer to use Vim. It’s your choice which editor to use. If you want to use the nano then you can use the command:

sudo nano /etc/environment
  1. In the environment file, add the following line at the end (Important: don’t change existing values.)
JAVA_HOME="/path/to/java"

Replace /path/to/java with the path you noted down in step 2.

In my case, the value is: /usr/lib/jvm/java-1.8.0-amazon-corretto/jre/bin/java

  1. Save and close the file.

If you are using the vim editor like me, then to save and exit the editor press ESE key and type:

!wq

This will save the changes and exit the editor.

  1. To apply the changes, run the following command in the terminal:
source /etc/environment

This will reload the environment variables.

  1. Finally, you can verify that the Java home path has been set correctly by running the following command:
echo $JAVA_HOME

This should output the path you set in step 4.

The Java home path should now be set permanently on your Ubuntu system.

Test Java development environment

Finally, to test that everything is working properly, open your IDE and create a new Java project. In the main method, type “System.out.println(“Hello, world!”);”. Run the program and you should see the output “Hello, world!” displayed in the console.

You can check how to run Hello World Program in Java in another blog post.

And that’s it! With these steps, you should now have a fully functional Java environment on your computer. Whether you’re just getting started with Java or you’re an experienced developer, this setup will give you everything you need to start creating your own Java programs.