Install Java

Install Java

Course Module

Set up the Java Development Kit (JDK) for Java programming and development.

← Back to All Modules

Recommended Prerequisites

Consider completing these modules before starting this one:

Completed
Learn Basic Command Line Usage

Understanding command line basics is essential for compiling and running Java programs using javac and java commands.

In Progress
Download and Install VS Code

VS Code with Java extensions provides a powerful development environment for Java programming.

Coming Soon
Install Python

Having experience with another programming language like Python can help you understand Java concepts more easily.

☕ Getting Started with Java

Java is a widely-used programming language required for many computer science courses. This guide will help you install the Java Development Kit (JDK) and set up your environment for Java development.

🔍 Installation Options

Choose the installation method that works best for your operating system:

📦 Method 1: Official Installer

🍺 Method 2: Using Homebrew (Mac)

If you have Homebrew installed on your Mac, you can use it to install OpenJDK:

brew install openjdk

✅ Verifying Installation

After installation, verify that Java is correctly installed by checking the version:

java -version

⚙️ Setting Up Environment Variables

After installation, you may need to set up environment variables:

💻 Windows Environment Setup

  • Right-click on This PC or My Computer and select Properties
  • Click on Advanced system settings
  • Click on Environment Variables
  • Under System Variables, find and select Path, then click Edit
  • Add the path to the JDK bin directory (e.g., C:\Program Files\Java\jdk-xx.x.x\bin)
  • Click OK to save changes

🍏 Mac/Linux Environment Setup

Add the following to your .bash_profile, .zshrc, or equivalent:

export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH

▶️ Compiling and Running Java Programs

To compile a Java program:

To run a compiled Java program:

javac YourProgram.java
java YourProgram

💻 Your First Java Program

Create a file named HelloWorld.java with the following content:

Compile and run the program with:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}
javac HelloWorld.java
java HelloWorld

📚 Additional Resources