Java Installation and Development Environment
Before you can write and run Java programs, you need to prepare your computer. Think of it like setting up a kitchen before you start cooking. You first need the right tools, and then you can start making food.
In this tutorial, you will learn how to install Java, what each tool does, and how to prepare your computer for writing Java programs.
What You Need Before Writing Java Programs
To create Java programs, you need two things:
- Java Development Kit (JDK)
- A code editor or an IDE
The JDK allows your computer to understand, compile, and run Java programs.
The code editor or IDE is where you write your Java code.
What is the JDK?
JDK stands for Java Development Kit.
It is the complete package required to develop Java applications.
Imagine you are building a house.
- The bricks are your Java code.
- The workers are the tools inside the JDK.
- The finished house is your working Java program.
Without the JDK, your computer cannot turn your Java code into a working program.
What Does the JDK Contain?
The JDK contains several tools.
The two most important ones are:
javac
This is the Java compiler.
It converts your Java source code into bytecode.
For example:
You write
HelloWorld.java
The compiler converts it into
HelloWorld.class
The .class file is what the Java Virtual Machine (JVM) understands.
java
This command runs your Java program.
Example:
java HelloWorld
This tells the JVM to execute your compiled program.
JDK, JRE and JVM
These three names often confuse beginners.
Let’s understand them using a simple example.
Imagine you buy a DVD movie.
- The movie is your Java program.
- The DVD player is the JRE.
- The motor inside the DVD player is the JVM.
- The movie studio that creates DVDs is the JDK.
Now let’s understand each one.
JVM (Java Virtual Machine)
The JVM is responsible for running Java programs.
It reads the bytecode (.class files) and executes it.
Without the JVM, a Java program cannot run.
JRE (Java Runtime Environment)
The JRE contains:
- JVM
- Supporting files and libraries needed to run Java programs
The JRE allows users to run Java applications.
It does not contain tools for writing or compiling Java programs.
JDK (Java Development Kit)
The JDK contains everything.
It includes:
- JRE
- JVM
- Java compiler
- Development tools
If you want to become a Java programmer, install the JDK.
You do not need to install the JRE separately because it is already included in the JDK.
Difference Between JDK, JRE and JVM
| JDK | JRE | JVM |
|---|---|---|
| Used to develop Java programs | Used to run Java programs | Executes Java bytecode |
| Contains compiler | Does not contain compiler | Does not compile code |
| Includes JRE | Includes JVM | Smallest part |
| Installed by developers | Used by end users | Works behind the scenes |
Downloading the JDK
You can download the latest JDK from Oracle’s official website or other trusted Java distributions.
Popular choices include:
- Oracle JDK
- OpenJDK
- Eclipse Temurin
For learning Java, any of these will work.
Installing the JDK
The installation process is similar to installing any normal software.
Steps:
- Download the installer.
- Double-click the installer.
- Keep clicking Next.
- Finish the installation.
The JDK is now installed on your computer.
What is the PATH Environment Variable?
After installing Java, your computer should know where Java is located.
This is done using the PATH environment variable.
Think of PATH as your computer’s contact list.
Suppose your friend asks,
“Where is Rahul’s house?”
If the address is saved in your phone, you can find it immediately.
Similarly, PATH stores the location of important programs.
When you type
java
your computer checks the PATH to find where Java is installed.
Without PATH, the computer may say:
'java' is not recognized as an internal or external command.
How to Set the PATH Variable
The exact steps depend on your operating system.
In general:
- Find the bin folder inside the JDK installation.
Example:
C:\Program Files\Java\jdk-21\bin
- Copy this path.
- Open the Environment Variables settings.
- Edit the PATH variable.
- Add the copied path.
- Save the changes.
- Restart Command Prompt or Terminal.
Now your computer knows where Java is installed.
Verifying the Installation
After installation, open:
- Command Prompt (Windows)
- Terminal (Linux/macOS)
Type:
java -version
If Java is installed correctly, you will see something like:
java version "21"
Now check the compiler.
Type:
javac -version
Example output:
javac 21
If both commands work, your Java installation is successful.
Choosing a Code Editor or IDE
You need a place to write your Java code.
There are two common options.
Code Editor
A code editor is lightweight and mainly used for writing code.
Examples:
- Visual Studio Code
- Notepad++
- Sublime Text
A code editor gives you basic features like syntax highlighting and file editing.
IDE (Integrated Development Environment)
An IDE is a complete software package for programming.
It provides many extra features such as:
- Code suggestions
- Error detection
- Debugging tools
- Project management
- Automatic code formatting
Popular Java IDEs include:
- IntelliJ IDEA
- Eclipse
- Apache NetBeans
Which One Should You Choose?
If you are just starting to learn Java, an IDE can make learning easier because it helps you spot mistakes and provides useful suggestions.
Many beginners choose IntelliJ IDEA Community Edition because it is free and offers an excellent experience for Java development.
As you become more comfortable with Java, you can also practice using a simple code editor and the command line. This helps you understand how Java programs are compiled and run behind the scenes.
Your Java Development Environment is Ready
Once you have:
- Installed the JDK
- Verified the installation using
java -versionandjavac -version - Set the PATH correctly (if required)
- Installed a code editor or IDE
your Java development environment is ready.
You can now start writing, compiling, and running your first Java program.
Summary
- Java programs are developed using the JDK.
- The JDK includes the JRE, JVM, compiler, and other development tools.
- The JVM executes Java bytecode.
- The JRE provides everything needed to run Java programs.
- The JDK is used to develop Java applications.
- The PATH environment variable helps your computer find Java commands.
- Use
java -versionandjavac -versionto verify the installation. - You can write Java programs using a code editor or an IDE such as IntelliJ IDEA, Eclipse, or Apache NetBeans.
- Once the JDK and an editor or IDE are installed, your Java development environment is ready for programming.