Nearby lessons
7 of 125Java - Environment Setup
- How to set up Java (PATH) on your computer
- How to write, save, compile and run your first program
- The meaning of every word in the main method
- The rules about class name and file name
- How to fix the common errors a beginner faces
Environment Setup is a core concept of the Java language. This lesson explains The Six Simple Steps, Setting the PATH (Why it is needed) and If You Have More Than One Java Version with complete, runnable code examples, clear step-by-step explanations, and common mistakes to avoid with exam-style MCQs at the end.
The Six Simple Steps
Preparing any Java application takes only six steps. Once you learn these six steps, you can run every program in this book:
- Install Java software — install the JDK (Chapter 1 explained how).
- Select a Java editor — Notepad, Notepad++, VS Code, or any editor where you type code.
- Write the Java program — type your code in the editor.
- Save the Java file — save with the exact name and the .java extension.
- Compile the Java file — use the javac command.
- Execute (run) the Java application — use the java command.
Setting the PATH (Why it is needed)
When you type javac or java in the command prompt, the computer searches for these programs. If it cannot find them, you get an error like 'javac' is not recognized. The PATH is a list of folders where the computer searches for programs. We must add the JDK's bin folder to the PATH.
- Right-click on This PC (or My Computer) and choose Properties.
- Click Advanced system settings, then click Environment Variables.
- Under System variables, find Path, select it and click Edit.
- Click New and paste the JDK bin folder, for example C:\Program Files\Java\jdk-21\bin.
- Click OK on all windows. Open a fresh command prompt and test with java -version.
If You Have More Than One Java Version
Sometimes a computer has many Java versions (Java 8, 11, 17...). A common exam question: if all of them are in the PATH, which one wins?
Answer: the one that appears first in the PATH order. The command prompt takes the first matching java it finds.
To switch between versions easily, create small batch files (.bat) — one per version:
If You Have More Than One Java Version
How to Install Java (Modern Steps)
To start your journey, you need the JDK on your computer. Here are the modern, simple steps:
- Open a browser and search for "Java JDK download" or go to the official site adoptium.net (free builds, recommended) or oracle.com/java. For college work, download the LTS version (Java 21 or Java 17).
- Choose the installer for your operating system (Windows / Linux / macOS).
- Download and run the installer. Click Next, Next and Finish. Default settings are fine.
- Open a command prompt (press Windows key, type cmd, press Enter).
- Type java -version and press Enter. If you see a version message, Java is installed correctly.
- Now type javac -version. This checks that the compiler is also available.
Editor vs IDE
An editor (Notepad, Notepad++, VS Code) is software to write and save programs. An IDE (Integrated Development Environment) is a complete toolkit — editor + compiler + debugger + project management together. Famous IDEs: Eclipse, IntelliJ IDEA, NetBeans.
| Tool | Examples | Best for |
|---|---|---|
| Editor | Notepad, Notepad++, VS Code | Learning, small programs |
| IDE | Eclipse, IntelliJ IDEA, NetBeans | Real projects, big applications |
More Useful javac Options
The compiler javac has handy options that the classic material teaches:
The -d option is special: when your file has a package statement, -d makes the compiler create the folder structure for the package automatically.
- Six steps: install JDK → choose editor → write program → save file → compile with javac → run with java.
- File name must match the public class name exactly, and must end with .java.
- javac creates a .class file (bytecode); java runs it.
- public static void main(String[] args) is the entry point of every program.
- Comments (//, /* */, /** */) are ignored by the compiler and are used for documentation.
- Most beginner errors are due to PATH, folder location, or spelling mistakes.