In this lesson of Java course, we will be setting up Java development environment. Before we start developing application in Java or start our journey with our course, we need to download and install JDK. We have already gone through the different components of the Java development environment and this lesson is focused on setting up the Java development environment.
There are different options to download the JDK for your local development. When using in production, you might want to check for the license, however for the development, we have the following high level options
We talked about it in the last lesson, JDK stands for Java Development Kit. JDK contains a number of tools which helps us in Java application development. Here are some of the main components of the JDK.
Download the JDK from Open JDK or Oracle site, make sure you download the correct installer based on your OS. Run the installer to install the JDK on your development environment.
JAVA_HOME
environment variableOne of the main step while setting up Java development environment is to set up the JAVA_HOME
environment variable.Set up the JAVA_HOME
environment variable to point to the directory where the JDK is installed. This step varies based on your operating system. Let’s see how to setup this on few OS.
JAVA_HOME
environment variable on windowHere are the step by step guide to set up the JAVA_HOME environment variable on window machine.
where java
on Command Prompt to check the JDK path.C:\Program Files\Java\jdkX
(where X
represents the version number).JAVA_HOME
.C:\Program Files\Java\jdkX
).JAVA_HOME
environment variable on macOS and Linuxecho $(/usr/libexec/java_home)
. This will display the path to the currently active JDK installation.export JAVA_HOME=/path/to/your/JDK
.Replace /path/to/your/JDK
with the actual path to your JDK installationTo set the JAVA_HOME variables permanently, we can follow these steps:
.bashrc
, .bash_profile
, or .zshrc
file in your home directory using a text editor.export JAVA_HOME=/path/to/your/JDK
. Save the file and close the text editor.To confirm the changes, run the following command in the terminal window
~ java -version
You will have some similar output:
The next step is to choose the IDE to write and manage your Java code. There are many popular options, here are the 2 top popular options:
Install any IDE of your choice. Once this is done, We need to configure the IDE. I will walk you through setting you your IntelliJ IDEA but you can follow any online article to setup JDK for Eclipse.
Launch IntelliJ IDEA and Choose “Configure” > “Project Defaults” > “Project Structure.”
Under “Project,” set the Project SDK to the JDK you installed
This will ensure that your IDE is all set for your first Java program. In the next lesson we will talk about creating our first Java program.
In this lesson, we followed the steps for setting up Java development environment. This is the first step to start our learning jounrey for Java application development. We will continue our learning journey from here. As always, the entire source code for this course is available on the GitHub repository.