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.
java and javac work at the command line, then compile and run a small program.
Key Terms
| Term | Meaning |
|---|---|
| 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 builds | Free 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:
HelloWorldandhelloworldare 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:
- Download the JDK installer.
- Run the installer.
- Set
PATHandJAVA_HOME(Windows option). - 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
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. Stringandintdeclare variables with a type.System.out.printlnprints 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
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
javafrom a different folder than the.classfile, or typedjava 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.
- Install the JDK (not just a JRE) so you have the
javaccompiler. - 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 →
javacto compile →javato run.