Before you can start writing Java code, you need to set up your development environment. This guide will walk you through installing the JDK and running your very first Java program.
Modern Java versions (JDK 17 or 21 LTS) are quite efficient, but ensure your system meets these minimum specs:
The JDK (Java Development Kit) allows you to compile and run Java programs. Follow these steps:
Go to the official Oracle Java Downloads page. Select your operating system (Windows, macOS, or Linux) and download the x64 Installer.
Open the downloaded file and follow the installation wizard. By default, Java is installed in C:\Program Files\Java\jdk-xx on Windows.
Open your Command Prompt (CMD) or Terminal and type the following command:
If you see the version number (e.g., "java version 21"), Java is successfully installed!
To run Java commands from any folder in your CMD, you must add Java to your system's Environment Variables.
Path and click Edit.bin folder (e.g., C:\Program Files\Java\jdk-21\bin).While you can write Java in Notepad, professional developers use **IDEs (Integrated Development Environments)** for better productivity.
Lightweight and great for beginners with Java extensions.
The most popular IDE for professional Java development.
A classic, powerful IDE used widely in the industry.
Let's write, compile, and run your first program manually to understand the process.
Step 1: Open Notepad and type the following code:
Step 2: Save the file as MyFirstProgram.java.
Important: The file name must exactly match the class name!
Step 3: Open CMD in the folder where you saved the file and type:
Output:
| Problem | Solution |
|---|---|
| 'javac' is not recognized | Your Environment Path is not set correctly. Refer to Step 3. |
| Class not found error | Ensure you are running the command from the correct folder. |
| Wrong Case Sensitivity | Java is case-sensitive. main is not the same as Main. |
Now that your computer is ready to speak Java, let's learn the basic rules of the language. In the next chapter, we will look at Java Syntax and how to write clean, error-free code.
Next: Java Syntax →