Stuck setting up Java on your PC? This guide gets you from zero to your first running Java program β step by step, with fixes for every common error.
Getting Started β’ Common Errors β’ IDE Comparison β’ What's Next
- What's Required for Java Programming?
- Recommended Setup for Beginners
- Step 1: Download and Install JDK
- Step 2: Verify Installation
- Step 3: Configure Environment Variables
- Step 4: Install Visual Studio Code
- Step 5: Install Java Extensions in VS Code
- Step 6: Install IntelliJ IDEA
- Your First Java Program
- Compile and Run from Terminal
- Important Naming Rule
- Common Problems and Fixes
- Which IDE Should You Use?
- Next Topics to Learn
- Contributing
- License
Before writing a single line of Java code, you need three things in place:
The JDK is the core package required to develop and run Java applications. It bundles together:
| Component | Purpose |
|---|---|
javac (Java Compiler) |
Converts your .java source code into bytecode |
| JRE (Java Runtime Environment) | Provides the libraries needed to run Java programs |
| JVM (Java Virtual Machine) | Executes the compiled bytecode on your machine |
| Standard Java Libraries | Pre-built classes (collections, I/O, utilities, etc.) |
β οΈ Without the JDK, Java programs cannot be compiled or executed β it's a non-negotiable first step.
An IDE (Integrated Development Environment) makes writing, running, and debugging code far easier than a plain text editor.
| IDE | Best For |
|---|---|
| IntelliJ IDEA | Beginners and serious Java learners (Recommended) |
| Visual Studio Code | Lightweight, flexible, multi-language workflows |
| Eclipse | Legacy enterprise projects |
- β Automatic project management
- β Smarter error detection
- β Intelligent code completion
- β One-click run/debug
Best for: students who want to learn Java seriously, with minimal configuration headaches.
- β Lightweight and fast
- β Highly customizable
β οΈ Requires manually installing Java extensions
Best for: students already comfortable in the VS Code ecosystem.
Get the JDK directly from Oracle:
π‘ You can also use the free, open-source Eclipse Temurin (Adoptium) build if you prefer not to create an Oracle account.
| File Type | Recommendation |
|---|---|
x64 Installer (.exe) |
β Best choice for most users |
x64 MSI Installer (.msi) |
Use for corporate/enterprise silent installs |
Compressed Archive (.zip) |
Advanced users who want a portable install |
Choose a file that looks like:
jdk-<version>_windows-x64_bin.exe
Example:
jdk-25_windows-x64_bin.exe
π Note: Oracle releases a new JDK version every 6 months, but only certain versions are LTS (Long-Term Support) β these get years of updates and are what most courses, universities, and production environments standardize on. As of mid-2026, JDK 21 and JDK 25 are the current LTS releases. Newer non-LTS versions (such as JDK 26) work fine too and are great for learning, but stick to an LTS version if you want maximum compatibility with tutorials, libraries, and course material.
- Double-click the downloaded installer
- Click Next
- Click Install
- Click Finish
Open Command Prompt and run:
java -versionExpected output (version number will match what you installed):
java version "25.0.1" 2025-09-16 LTSCheck the compiler too:
javac -versionExpected output:
javac 25.0.1β If both commands return version info, your JDK is installed correctly β move on to Step 3 only if you see an error.
If java or javac aren't recognized, you need to set up your environment variables manually.
Open the Start Menu and search for:
Edit the system environment variables
Click Environment Variables, then under System Variables, click New:
| Field | Value |
|---|---|
| Variable Name | JAVA_HOME |
| Variable Value | C:\Program Files\Java\jdk-25 |
β οΈ Replace the path above with your actual JDK installation folder. It usually lives underC:\Program Files\Java\. Open File Explorer and check the exact folder name before copying this.
- In the same Environment Variables window, select Path under System Variables
- Click Edit β New
- Add:
%JAVA_HOME%\bin
- Click OK on all open windows to save.
Open a brand-new Command Prompt window (environment changes don't apply to already-open windows):
echo %JAVA_HOME%Expected:
C:\Program Files\Java\jdk-25Check the binary path:
where javaExpected:
C:\Program Files\Java\jdk-25\bin\java.exeDownload VS Code from:
Run the installer with default settings.
- Open VS Code
- Go to the Extensions panel (
Ctrl+Shift+X) - Search for:
Extension Pack for Java
- Install the official package published by Microsoft
This pack bundles:
- π€ Language Support for Java
- π Debugger for Java
- π¦ Maven Support
- β Java Test Runner
- π§° Project Manager for Java
Download from:
π jetbrains.com/idea/download
Choose:
IntelliJ IDEA Community Edition (Free & Open Source)
Install with default settings.
Create a new file named:
Hello.java
Write the following code:
public class Hello {
public static void main(String[] args) {
System.out.println("Java is working!");
}
}Compile the source file into bytecode:
javac Hello.javaThis generates a Hello.class file.
Run the compiled program:
java HelloOutput:
Java is working!
The public class name must exactly match the file name (case-sensitive).
β Correct:
public class Hello { ... }File name: Hello.java
β Incorrect:
public class Test { ... }File name: Hello.java
This mismatch will throw a compilation error:
error: class Test is public, should be declared in a file named Test.java
'java' is not recognized as an internal or external command, operable program or batch file.Fix:
- β Verify JDK is actually installed
- β
Configure
JAVA_HOMEcorrectly (see Step 3) - β
Add
%JAVA_HOME%\binto yourPath - β Close and reopen Command Prompt (old windows won't see the new PATH)
Fix:
This means the JDK's bin folder isn't on your PATH. Add:
%JAVA_HOME%\bin
to your system Path variable, then open a fresh terminal.
Fix:
- β Install the Extension Pack for Java (see Step 5)
- β Restart VS Code completely
- β
Confirm
JAVA_HOMEis set correctly β VS Code's Java extensions rely on it
This happens when you compile with a newer JDK but try to run with an older JRE.
Fix:
- β Make sure only one JDK version is on your PATH
- β
Run
java -versionandjavac -versionand confirm they match
| Feature | VS Code | IntelliJ IDEA |
|---|---|---|
| Lightweight | β | β |
| Easy Setup | β Works out of the box | |
| Java Support | Good | Excellent |
| Beginner Friendly | Good | Best |
| Professional Java Development | Good | Excellent |
| If you are... | Use... |
|---|---|
| A complete beginner | IntelliJ IDEA |
| Coding in multiple languages | VS Code |
| Working professionally with Java | IntelliJ IDEA |
Once your environment is ready, follow this learning path:
- Variables and Data Types
- Input using
Scanner - Operators
- Conditional Statements (
if,else,switch) - Loops (
for,while,do-while) - Arrays
- Methods
- Classes and Objects
- Inheritance
- Polymorphism
- Exception Handling
- Collections Framework (
ArrayList,HashMap, etc.)
Found an error, an outdated link, or want to add a setup guide for macOS or Linux? Contributions are welcome!
- Fork this repository
- Create a new branch (
git checkout -b improvement/your-topic) - Commit your changes
- Open a Pull Request
This project is licensed under the MIT License β feel free to use, share, and adapt it for your own learning resources.