Java Language – 1 – Installing Java

Java Fundamentals – Installing Java
Introduction

Installing Java is the first crucial step in your journey to becoming a Java developer. Java is a versatile and widely-used programming language known for its portability and flexibility. In this guide, we will walk you through the process of installing Java on your system, regardless of whether you are using Windows, macOS, or Linux. We’ve got you covered.

Prerequisites

Before we begin, ensure you have an active internet connection, as we’ll be downloading Java directly from Oracle’s official website. Additionally, make sure your system meets the hardware and software requirements for the Java version you intend to install.

Step 1: Download Java Development Kit (JDK)

The Java Development Kit (JDK) is essential for Java development, as it includes the Java Runtime Environment (JRE) and important tools like the Java compiler (javac) and debugger (jdb). To download the JDK, follow these steps:


1. Visit the Oracle JDK download page by clicking here.
2. Accept the Oracle Technology Network License Agreement.
3. Select the appropriate JDK version for your system (Windows, macOS, or Linux).
4. Click the download link to initiate the download.
Step 2: Install the JDK

Once the JDK installation file is downloaded, follow these installation instructions specific to your operating system.

For Windows:

1. Double-click the downloaded .exe file to run the installer.
2. Follow the on-screen instructions to complete the installation.
For macOS:

1. Double-click the downloaded .dmg file to mount it.
2. Drag and drop the JDK package to the Applications folder.
3. The JDK is now installed on your system.
For Linux:

1. Open your terminal.
2. Navigate to the directory where the JDK installation file is located.
3. Run the following command to make the installation file executable:
chmod +x filename
4. Execute the installation file with the following command (replace filename with the actual filename):
./filename
5. Follow the on-screen instructions to complete the installation.
Step 3: Verify the JDK Installation

To ensure that the JDK has been successfully installed, open your terminal or command prompt and type the following command:


java -version

You should see information about the installed Java version. This confirms that the JDK has been installed on your system.

Step 4: Set Environment Variables

To use Java and its tools efficiently, it’s important to set the PATH environment variable. This allows your operating system to locate the Java executables easily.

For Windows:

1. Right-click on "This PC" or "My Computer" and select "Properties."
2. Click on "Advanced system settings."
3. Click the "Environment Variables" button.
4. In the "System Variables" section, find the "Path" variable and click "Edit."
5. Add the path to the "bin" directory of your JDK installation (e.g., C:\Program Files\Java\jdk1.8.0_291\bin).
6. Click "OK" to save the changes.
For macOS and Linux:

1. Open your terminal.
2. Edit the .bashrc or .zshrc file, depending on your shell:
vi ~/.bashrc or vi ~/.zshrc
3. Add the following line to export the JDK path (replace /path/to/jdk with your actual path):
export PATH=/path/to/jdk/bin:$PATH
4. Save and exit the editor.
5. Source the updated file or restart your terminal:
source ~/.bashrc or source ~/.zshrc
Step 5: Verify Environment Variables

To verify that the PATH environment variable has been correctly set, open a new terminal or command prompt and run the following command:


echo $PATH

You should see the path to your JDK’s “bin” directory included in the output. This confirms that the environment variable has been set correctly.

Conclusion

Congratulations! You have successfully installed Java on your system and configured the necessary environment variables. You are now ready to start developing Java applications and exploring the world of Java programming.