
You can go from zero to running Java code in about 20 minutes. This guide walks through the entire process: downloading Java, installing it on your system, and writing a program that actually runs.
These instructions work for Windows, Mac, and Linux. Pick your operating system and follow along.
What You Need to Install
Java requires one piece of software: the Java Development Kit (JDK). The JDK includes everything you need to write, compile, and run Java programs.
You have two main options for downloading the JDK:
Oracle JDK – The official version from Oracle. Free for development and personal use. Download from oracle.com/java/technologies/downloads
Eclipse Temurin – An open-source alternative maintained by the Adoptium project. Completely free for any use. Download from adoptium.net
Both work identically for learning. Temurin has simpler licensing, so that’s what I recommend for beginners.
Download Java 21 (the current Long-Term Support version) unless you have a specific reason to choose differently.
Installing on Windows
Step 1: Download the installer
Go to adoptium.net and click the download button. The site detects your operating system automatically. You want the .msi installer for Windows.
Step 2: Run the installer
Double-click the downloaded file. When prompted, select these options:
- Add to PATH – Yes (this lets you run Java from any folder)
- Set JAVA_HOME – Yes (some tools need this)
- Associate .jar files – Optional, but convenient
Click through the rest of the installer with default settings.
Step 3: Verify the installation
Open Command Prompt (press Windows key, type “cmd”, press Enter) and run:
java -version
You should see output like:
openjdk version "21.0.2" 2024-01-16 LTS
OpenJDK Runtime Environment Temurin-21.0.2+13 (build 21.0.2+13-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.2+13 (build 21.0.2+13-LTS, mixed mode)
The exact version numbers may differ. If you see version information, Java is installed correctly.
If you get “java is not recognized as an internal or external command,” the PATH wasn’t set properly. Restart your computer first. If that doesn’t fix it, you’ll need to add Java to your PATH manually (search “add to PATH Windows” for instructions).
Installing on Mac
Step 1: Download the installer
Go to adoptium.net. Download the .pkg file for macOS. If you have an M1, M2, or M3 Mac (2020 or newer), choose the “aarch64” version. For older Intel Macs, choose “x64”.
Step 2: Run the installer
Double-click the downloaded .pkg file and follow the prompts. The Mac installer handles PATH configuration automatically.
Step 3: Verify the installation
Open Terminal (Applications > Utilities > Terminal, or use Spotlight) and run:
java -version
You should see version information similar to the Windows example above.
Alternative: Homebrew
If you use Homebrew, installation is one command:
brew install --cask temurin
Installing on Linux
Most Linux distributions include Java in their package managers.
Ubuntu/Debian:
sudo apt update
sudo apt install openjdk-21-jdk
Fedora:
sudo dnf install java-21-openjdk-devel
Arch Linux:
sudo pacman -S jdk-openjdk
Verify with java -version after installation completes.
Writing Your First Program
Time to write actual code. You can use any text editor for this. Notepad on Windows works fine. So does TextEdit on Mac (switch to plain text mode first: Format > Make Plain Text). On Linux, use whatever editor you prefer.
Create a new file and type this exactly:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Save the file as HelloWorld.java in a location you can find easily. Your Desktop or Documents folder works fine.
Important: The filename must match the class name exactly, including capitalization. The file is HelloWorld.java because the class is named HelloWorld.
Running Your Program
Open your terminal or command prompt and navigate to the folder containing your file. If you saved it to your Desktop:
Windows:
cd Desktop
Mac/Linux:
cd ~/Desktop
Now compile the program:
javac HelloWorld.java
If there are no errors, this command produces no output. It creates a new file called HelloWorld.class in the same folder. This is the compiled bytecode that Java can run.
If you see error messages, check that you typed the code exactly as shown. Java is picky about capitalization, semicolons, and curly braces.
Run the compiled program:
java HelloWorld
Note: Use HelloWorld without the .java or .class extension.
Output:
Hello, World!
You just ran your first Java program.
Understanding the Code
That five-line program has several parts worth understanding:
public class HelloWorld – Defines a class named HelloWorld. Every Java program needs at least one class. The class name must match the filename.
public static void main(String[] args) – The main method. This is where your program starts running. Every Java application needs a main method with this exact signature.
System.out.println("Hello, World!"); – Prints text to the screen. System.out refers to the standard output (your terminal). println prints the text and adds a new line.
The curly braces { } define where each block of code starts and ends. The semicolon ; marks the end of a statement.
Setting Up an IDE (Optional but Recommended)
Writing Java in a plain text editor works, but an Integrated Development Environment (IDE) makes everything easier. IDEs provide syntax highlighting, error detection, code completion, and debugging tools.
Three popular choices:
IntelliJ IDEA Community Edition – Free and widely considered the best Java IDE. Download from jetbrains.com/idea. The Community Edition has everything beginners need.
Visual Studio Code – Free, lightweight, and works for many languages. Install the “Extension Pack for Java” from the extensions marketplace. Download from code.visualstudio.com.
Eclipse – Free and open source. Been around since 2001. Some find the interface dated, but it’s capable and well-documented. Download from eclipse.org/downloads.
For beginners, I suggest IntelliJ IDEA Community Edition. The learning curve is gentle, and professional Java developers often use the paid version, so the skills transfer.
Common Installation Problems
“java is not recognized” or “command not found”
Java isn’t in your system PATH. On Windows, restart your computer after installation. If that doesn’t work, you need to add the Java bin folder to your PATH environment variable manually.
“javac is not recognized” but “java” works
You installed the Java Runtime Environment (JRE) instead of the Java Development Kit (JDK). The JRE can run Java programs but can’t compile them. Uninstall it and install the JDK instead.
Wrong version showing up
You may have multiple Java versions installed. On Windows, the most recently installed version usually takes priority. On Mac/Linux, you can use which java to see which installation is being used.
Mac: “Cannot be opened because it is from an unidentified developer”
Go to System Preferences > Security & Privacy > General. Click “Open Anyway” next to the blocked application message.
Next Steps
With Java installed and your first program running, you’re ready to start learning the language. Try modifying the HelloWorld program:
public class HelloWorld {
public static void main(String[] args) {
String name = "Alice";
int age = 25;
System.out.println("Hello, " + name + "!");
System.out.println("You are " + age + " years old.");
}
}
This version introduces variables. String holds text. int holds whole numbers. The + operator joins strings together.
Save, compile with javac HelloWorld.java, and run with java HelloWorld.
From here, learn about variables, data types, conditionals (if/else), and loops. These fundamentals apply to almost every programming language.
Related: What is Java? A Beginner’s Guide | Java vs Python: Which Should You Learn First?
Sources
- Eclipse Adoptium. “Installation Guide.” adoptium.net
- Oracle. “Java SE Downloads.” oracle.com
- JetBrains. “IntelliJ IDEA.” jetbrains.com

