All Tech Guides

Tech Guide

Install Java and Write Your First Program

An introduction to Java, how to install the Java Development Kit (JDK) on Windows, macOS, and Linux, and a beginner example you compile and run from the command line.

Programming Beginner Updated October 2026

Disclaimer & Important Cautions

These Tech Guides and instructions are provided in good faith as a general educational guide. Technology changes over time, and settings, software versions, installation steps, and security practices may vary by system.

I cannot guarantee that these steps will work in every environment, and I am not responsible for data loss, configuration problems, system errors, security issues, downtime, or other problems that may result from following this guide.

  • Download the JDK only from trusted sources such as Adoptium or Oracle.
  • Use administrator privileges carefully when installing software.
  • Be careful when editing system environment variables such as PATH and JAVA_HOME.
  • Uninstall old Java versions you no longer need, since outdated versions may have security issues.
  • When in doubt, consult official documentation or a qualified technician.

Overview

Java is a general-purpose, object-oriented programming language first released by Sun Microsystems in 1995 and now maintained by Oracle and the open-source OpenJDK community. Java programs are compiled into bytecode that runs on the Java Virtual Machine (JVM), so the same program runs on Windows, macOS, and Linux without changes: "write once, run anywhere."

Java is used for enterprise and web back-end systems, Android apps, big-data tools, and teaching programming. In this guide you will install the Java Development Kit (JDK), confirm it works, and write, compile, and run a first program.

Main idea: Install a current LTS (long-term support) JDK, confirm that java and javac work at the command line, then compile and run a small program.

Key Terms

TermMeaning
JDK (Java Development Kit)Everything you need to write Java: the compiler (javac), the runtime (java), and other tools. Install this one.
JRE (Java Runtime Environment)Only what is needed to run Java programs. The JDK already includes it.
JVM (Java Virtual Machine)The engine that runs compiled Java bytecode on your computer.
LTS (Long-Term Support)A Java version that receives updates for several years. Java 25 (September 2025) is the current LTS; Java 21 and 17 are earlier LTS versions.
OpenJDK buildsFree builds of Java from several vendors. Eclipse Temurin from Adoptium is a popular free, open-source choice. Oracle also offers its own JDK.

Requirements

  • A Windows, macOS, or Linux computer (64-bit).
  • Administrator privileges to install software.
  • Internet access.
  • A plain-text or code editor, such as Notepad, TextEdit (in plain-text mode), or Visual Studio Code.

Important Notes

  • Your instructor or project may require a specific Java version. If so, install that version instead of the latest LTS.
  • Java may already be installed on your computer. Check first (Step 1 below).
  • Java is case-sensitive: HelloWorld and helloworld are different names.

Java Installation Instructions

Step 1: Check whether Java is already installed

Open a command line window (Command Prompt or PowerShell on Windows, Terminal on Mac and Linux) and enter:

java -version
javac -version

If both commands print a version number of 25 or higher (or the version your class requires), Java is ready and you can skip to the Beginner Example. If you see an error such as 'java' is not recognized or command not found, or only java works and javac does not, install the JDK below.

Choose the tab for your operating system:

Installing the Java Development Kit

Click the tab above for your operating system. This guide uses Eclipse Temurin, a free OpenJDK build from Adoptium.

The guide covers these major tasks:

  1. Download the JDK installer.
  2. Run the installer.
  3. Set PATH and JAVA_HOME (Windows option).
  4. Confirm the installation.

Step 2: Confirm the installation

Open a new command line window and enter:

java -version
javac -version

Both commands should print a version number, for example:

openjdk version "25.0.1" 2025-10-21 LTS
javac 25.0.1
Check yourself: Both commands print version 25 (the exact update number may differ).

Beginner Example: Hello, Java

Every Java program is built from classes. The program starts running at a method named main. You write the source code in a .java file, compile it with javac into a .class file, and run it with java.

Step 1: Create a project folder

Create a folder for your Java work, for example JavaProjects in your Documents folder.

Step 2: Write the program

In your editor, create a file named exactly HelloWorld.java in that folder and enter:

public class HelloWorld {

    public static void main(String[] args) {
        String name = "Java";
        int year = 1995;

        System.out.println("Hello, " + name + "!");
        System.out.println(name + " was first released in " + year + ".");

        for (int i = 1; i <= 3; i++) {
            System.out.println("Count: " + i);
        }
    }
}

Notice:

  • The file name must match the class name: HelloWorld → HelloWorld.java.
  • String and int declare variables with a type.
  • System.out.println prints a line of text.
  • Every statement ends with a semicolon, and curly braces { } group code into blocks.

Step 3: Compile and run

In the command line, move into your folder (adjust the path to match where you created it):

cd Documents/JavaProjects

Compile the program. This creates HelloWorld.class:

javac HelloWorld.java

Run it. Note that you type the class name, without .java or .class:

java HelloWorld

Output:

Hello, Java!
Java was first released in 1995.
Count: 1
Count: 2
Count: 3

Shortcut: for a single-file program, current Java versions can compile and run in one step:

java HelloWorld.java
Check yourself: Change the value of name, save, compile, and run again. The output should change to match.

Common Errors

  • class HelloWorld is public, should be declared in a file named HelloWorld.java: the file name and class name don't match.
  • ';' expected: a statement is missing its semicolon. The error message gives the line number.
  • Could not find or load main class: you ran java from a different folder than the .class file, or typed java HelloWorld.class.

Next Steps

  • Install Visual Studio Code and its Extension Pack for Java, or another Java IDE such as IntelliJ IDEA Community Edition or Eclipse.
  • Track your Java projects with Git and GitHub.
  • Work through Oracle's free tutorials at dev.java/learn.
Final Notes:
  • Install the JDK (not just a JRE) so you have the javac compiler.
  • Use a current LTS version, such as Java 25, unless your class requires another.
  • The file name must match the public class name.
  • The basic cycle is: edit → javac to compile → java to run.
Explore more technology resources

Return to the complete collection of installation and configuration guides.

Browse All Tech Guides