Your path to becoming an Ethical Hacker! Hacking Academy Try It Now!

Setting up the environment in Java

Learn how to set up the Java environment for development. Step-by-step guide for configuring JDK, JAVA_HOME, and PATH variables.
Java is a common computer programming language that is concurrent, class-based, and object-oriented. Java applications are compiled into bytecode that can run on any Java Virtual Machine (JVM) regardless of computer architecture. The latest version is Java 21.

Setting up the environment in Java


Due to differences in operating system configurations, the Java environment settings differ between Linux and Windows. However, Java itself is platform independent. Before setting up your environment, it is important to understand some key concepts as shown in the image below:

Setting up the environment in Java

  • JDK (Java Development Kit) : JDK is designed for software developers and contains tools such as Java, Javadoc, JAR, and Debug compiler. Used to develop Java applications.
  • JRE (Java Runtime Environment): JRE contains the parts of Java libraries required to run Java programs. It is intended for end users who want to run Java applications. JRE is a subset of JDK.
  • JVM (Java Virtual Machine): JVM is an abstract machine that provides an execution environment for executing Java bytecode. It is a specification that allows Java programs to run on a variety of hardware and software platforms.

Now let's discuss the steps for setting up the Java environment using visual aids. Let's illustrate visual aids using the Windows operating system.

Actions: Here we will suggest actions for the three different operating systems listed:

  1. Windows operating system
  2. Linux operating system
  3. macOS operating system

A. Windows operating system

The steps for setting up the Windows operating system environment are as follows:

Step 1: Download Java 8 JDK from the official website. Click on the first link for Windows (32-bit) or the last link for Windows (64-bit) as highlighted below.

Setting up the environment in Java

Step 2: After clicking the download link, a download prompt will appear. Accept the terms and conditions, then click on the download button to start downloading the JDK.

Setting up the environment in Java

Step 3: If you have an Oracle account, sign in. If you don't have one, you'll need to create an account and then sign in to proceed with the download.

Setting up the environment in Java

Step 4: Your download will start automatically after signing in. If it doesn't, click on the previous link again to initiate the download.

Setting up the environment in Java

Step 5: After downloading, run the JDK-8u application (.exe file) and follow the instructions to install Java on your machine. Once Java is installed, you'll need to set up the environment variable.

Step 6: Go to Control Panel -> System and Security -> System. Under the Advanced System Setting option, click on Environment Variables as highlighted below.

Setting up the environment in Java

Step 7: Now, you need to add the Java environment path to the "Path" variable under System variables. Select the "Path" variable and click on the Edit button as highlighted below.

Setting up the environment in Java

Step 8: In the list of paths, click on the New button, and then add the path where Java is installed. By default, Java is installed in the "C:\Program Files\Java\jdk\bin" folder OR "C:\Program Files(x86)\Java\jdk\bin". If you have installed Java in a different location, add that path.

Setting up the environment in Java

Step 9: Click on OK, then save the settings, and you're done! To check if the installation was successful, open the command prompt and type `javac -version`. You should see the version of Java that is running on your machine.

Note: To verify that the compiler is set up correctly, type `javac` in the command prompt. You should see a list of options related to `javac`.

B. Linux Operating System

There are several ways to install Java on Linux. But we will refer to the easiest way to install java using terminal. Linux we install Openjdk. Openjdk is a free and open source in Java programming. The steps for setting up a Linux operating system environment are as follows:

Step 1: Open Terminal
Go to Applications -> Accessories -> Terminal.

Step 2: Install OpenJDK
Type the following command in the terminal:

sudo apt-get install openjdk-8-jdk

Step 3: Set JAVA_HOME Environment Variable
Set the JAVA_HOME environment variable by typing the following command in the terminal (replace the path with your installation path if different):

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk

Step 4: Set PATH Environment Variable
Set the PATH environment variable by typing the following command in the terminal (replace the path with your installation path if different):

export PATH=$PATH:/usr/lib/jvm/java-8-openjdk/bin

Step 5: Verify Installation
To check if Java is installed correctly, type the following command in the terminal:

java -version

Additional Tools:

Notepad/Gedit: Simple text editors for writing Java programs. Notepad is available on Windows, and Gedit is available on Linux.
Eclipse IDE: A widely used Integrated Development Environment (IDE) for Java development. Download Eclipse from their website.

That's it! You've successfully set up Java on your Linux system using OpenJDK.

C. MacOS Operating System

Step 1: To begin, open the terminal either from the application folder or by pressing the "command" and "shift" keys simultaneously and typing the initials of the terminal, then pressing Enter.

It's recommended to have a package manager like Homebrew installed on your machine. This allows you to easily install software directly from the terminal using simple commands.

Next, to configure Java, enter the command `java --version` in the terminal. If Java is not set up, a message will appear indicating that it is not installed. Once Java is set up, running `java --version` and `javac --version` commands will display the installed version.

Setting up the environment in Java

Step 2: After installing the JDK, the next step is to set up the `JAVA_HOME` environment variable. To do this, you'll need to check if the `bash_profile` file exists. You can do this by using the command `ls -al` in the terminal. If the `bash_profile` file is not found, you'll need to create it. This file allows you to set up the `JAVA_HOME` variable and ensures that it is correctly configured.

Setting up the environment in Java

Step 3: Set the home java variable. If it is not installed in the terminal, use the following command to check or set it:

echo $JAVA_HOME

Setting up the environment in Java

If it is empty, the java home variable is not set, as shown in the image above.

Step 4. Install bash_profile

Be sure to go to the root directory of your terminal and type the command "touch ./bash_profile"

Setting up the environment in Java

You will now see the bash profile created on your computer as shown in step 2. This can be confirmed by typing the following command:

ls-al

Step 5. Edit the .bash_profile created by java, simply type the media highlighted commands below and enter them like this:

export JAVA_HOME=$(/usr/libexec/java_home)
// No need to remember this command

Setting up the environment in Java

Save this file and restart the terminal by closing it.

Step 6: Enter these two commands to confirm if it is installed.

source.bash_profile
echo $JAVA_HOME

Setting up the environment in Java

From the media above you can see that all the java variables are set because there was an empty space at the top.

إرسال تعليق

Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.