Before you start developing Java applications, you need a Java Development Kit (JDK) installed on your computer. The JDK provides the Java compiler, runtime, development tools, and other utilities required to create and run Java applications.
After installing the JDK, you can configure environment variables such as JAVA_HOME and PATH. You can then choose a development environment such as IntelliJ IDEA, Eclipse, or Visual Studio Code.
The complete setup can be summarized as:
Install JDK
↓
Configure JAVA_HOME
↓
Configure PATH
↓
Check Java Installation
↓
Choose an IDE / Code Editor
↓
Create and Run Java Programs
Installing JDK on Windows
Windows users can install a JDK from a Java distribution such as Oracle JDK, OpenJDK, Eclipse Temurin, Amazon Corretto, or another compatible distribution.
Download a JDK version appropriate for your project and operating system. For a new project, an LTS release is often a practical choice because it has a longer support period from the relevant vendor.
After downloading the Windows installer, open it and follow the installation wizard.
The JDK is commonly installed in a directory similar to:
C:\Program Files\Java\jdk-21
The exact directory depends on the JDK distribution and version.
Verify the Windows Installation
Open Command Prompt or PowerShell and run:
java -version
You should see information about the installed Java runtime.
Then check the Java compiler:
javac -version
If both commands display a version, the JDK is available from your terminal.
For example:
java version "21"
javac 21
The exact output will depend on your installed JDK.
Installing JDK on Linux
Linux distributions generally provide JDK packages through their package managers.
For Ubuntu or Debian-based systems, you can install OpenJDK with:
sudo apt update
sudo apt install openjdk-21-jdk
After installation, verify Java:
java -version
Then check the compiler:
javac -version
The exact package name can vary depending on the Linux distribution and the Java version available in its repositories.
Finding the Java Installation on Linux
You can use commands such as:
which java
and:
which javac
You can also inspect the configured Java installations on systems that provide the update-alternatives utility:
update-alternatives --config java
This can be useful when multiple Java versions are installed.
Setting JAVA_HOME
JAVA_HOME is an environment variable that points to the JDK installation directory.
Many Java-based development tools and build systems use this variable to locate the JDK.
For example, a Windows installation might use:
C:\Program Files\Java\jdk-21
A Linux installation might use a path similar to:
/usr/lib/jvm/java-21-openjdk-amd64
The exact path depends on your JDK distribution and installation method.
Setting JAVA_HOME on Windows
Open Windows search and look for:
Environment Variables
Then open:
Edit the system environment variables → Environment Variables
Under User variables or System variables, select New and create:
Variable name:
JAVA_HOME
Set the value to your JDK installation directory, for example:
C:\Program Files\Java\jdk-21
Do not include the bin directory in JAVA_HOME.
Correct:
C:\Program Files\Java\jdk-21
Not:
C:\Program Files\Java\jdk-21\bin
Setting JAVA_HOME on Linux
You can temporarily set it in a terminal:
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
To make it persistent for a Bash shell, add the appropriate line to your shell configuration file such as ~/.bashrc:
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
Then reload the configuration:
source ~/.bashrc
The actual JDK path should be replaced with the path on your system.
You can check the variable with:
echo $JAVA_HOME
Setting PATH
The PATH environment variable tells the operating system where it can find executable commands.
Java commands such as:
java
javac
jar
javadoc
are located in the JDK’s bin directory.
For example:
C:\Program Files\Java\jdk-21\bin
on Windows.
Setting PATH on Windows
Open the Environment Variables window and edit the Path variable.
Add:
%JAVA_HOME%\bin
Using %JAVA_HOME%\bin is convenient because you can change the JDK location through JAVA_HOME without having to rewrite the complete path.
After modifying environment variables, open a new Command Prompt or PowerShell window.
Then run:
java -version
and:
javac -version
Setting PATH on Linux
If JAVA_HOME is already configured, you can add the JDK’s bin directory to the PATH:
export PATH="$JAVA_HOME/bin:$PATH"
To make the setting persistent, place the appropriate export commands in your shell configuration file.
For example:
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64
export PATH="$JAVA_HOME/bin:$PATH"
Then reload the configuration:
source ~/.bashrc
Checking Java Installation
After installing and configuring the JDK, it is important to verify that both the runtime and compiler are working.
Run:
java -version
This checks the Java runtime.
Then:
javac -version
This checks the Java compiler.
You can also check the location of the executable.
On Windows:
where java
On Linux:
which java
If you have multiple Java installations, these commands can help you identify which executable your terminal is currently using.
Creating Your First Java Program
Once the JDK is installed, you can test the complete development environment.
Create a file named:
Hello.java
Add:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
Compile the program:
javac Hello.java
If compilation succeeds, a file named:
Hello.class
will normally be created.
Run the program:
java Hello
You should see:
Hello, Java!
This confirms that the basic Java compilation and execution process is working.
Installing IntelliJ IDEA
IntelliJ IDEA is a popular IDE for Java development. It provides many features that make software development easier, including code completion, debugging, project management, refactoring, testing, and integration with build tools.
Download and install IntelliJ IDEA for your operating system.
After opening IntelliJ IDEA, create a new Java project.
During project creation, select a compatible JDK. IntelliJ IDEA can use a JDK already installed on your computer, and depending on the version and configuration, it may also provide options for obtaining a JDK.
Once the project is created, you can create a Java class such as:
public class Main {
public static void main(String[] args) {
System.out.println("Hello from IntelliJ IDEA!");
}
}
Run the program using the Run button provided by the IDE.
Why Use IntelliJ IDEA?
IntelliJ IDEA is useful because it provides:
- Intelligent code completion
- Error detection
- Debugging
- Refactoring
- Git integration
- Maven and Gradle support
- JUnit integration
- Spring and Spring Boot support
- Project management
It is particularly useful when working on larger Java applications.
Installing Eclipse
Eclipse is another widely used IDE for Java development.
After installing Eclipse, start the IDE and select a workspace location. Create a Java project and configure the JDK you want the project to use.
You can then create a Java class:
public class Main {
public static void main(String[] args) {
System.out.println("Hello from Eclipse!");
}
}
Run the program using Eclipse’s Run functionality.
Why Use Eclipse?
Eclipse provides features such as:
- Java code completion
- Debugging
- Project management
- Refactoring
- Git integration
- Maven and Gradle support
- Testing support
- Plugin-based extensions
Eclipse has been widely used in professional Java development and remains an important Java IDE.
Using VS Code for Java
Visual Studio Code (VS Code) is a lightweight code editor that can also provide a complete Java development experience when the appropriate extensions are installed.
First, install VS Code and make sure a compatible JDK is installed.
Then install Java extensions from the VS Code Extensions marketplace. A convenient option is the Extension Pack for Java, which bundles commonly used Java development extensions.
After installing the extensions, VS Code can provide features such as:
- Syntax highlighting
- Code completion
- Error detection
- Debugging
- Java project support
- Unit testing
- Maven support
- Gradle support
- Code navigation
- Refactoring
Creating a Java Program in VS Code
Create a folder for your Java project and open it in VS Code.
Create:
Hello.java
Add:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello from VS Code!");
}
}
VS Code should recognize the Java file and provide Java development features through the installed extensions.
You can run the program using the Run option or through the integrated terminal:
javac Hello.java
java Hello
VS Code and Maven Projects
VS Code can also be used for larger Java projects.
For example, a Maven project may contain:
my-java-project/
├── pom.xml
└── src/
├── main/
│ └── java/
└── test/
└── java/
The pom.xml file contains project configuration and dependencies.
VS Code’s Java extensions can provide project navigation, dependency support, testing, and other features for Maven-based projects.
Choosing a Java Development Environment
All three environments can be used for Java development, but they provide different experiences.
| Feature | IntelliJ IDEA | Eclipse | VS Code |
|---|---|---|---|
| Type | Full IDE | Full IDE | Code editor with extensions |
| Java Support | Excellent | Excellent | Excellent with extensions |
| Beginner Friendly | Yes | Yes | Yes |
| Debugging | Yes | Yes | Yes |
| Maven | Yes | Yes | Yes |
| Gradle | Yes | Yes | Yes |
| Git | Yes | Yes | Yes |
| Spring Support | Strong | Strong | Available through extensions |
| Lightweight | Moderate | Moderate | Generally lightweight |
The choice depends on your preferences and project requirements. You can learn Java successfully with any of these environments.
Common Java Setup Problems
Beginners sometimes encounter problems after installing Java. Most of these problems are related to environment configuration.
'java' is not recognized
On Windows, this usually means the Java executable cannot be found through the current PATH, or the terminal was opened before the environment variables were updated.
Check that the JDK’s bin directory is correctly included in PATH, then open a new terminal.
javac is not recognized
If java works but javac does not, check whether the JDK is installed correctly and whether the JDK’s bin directory is available through PATH.
Remember that javac is the Java compiler and is provided by the JDK.
Wrong Java Version
If you have multiple Java versions installed, your terminal or IDE may be using a different JDK than you expect.
Check:
java -version
javac -version
On Windows, you can also use:
where java
On Linux:
which java
Then check your IDE’s configured JDK.
Complete Java Setup Workflow
A typical Java development setup looks like this:
JDK
↓
JAVA_HOME + PATH
↓
Verify java / javac
↓
Choose Development Tool
↙ ↓ ↘
IntelliJ Eclipse VS Code
↘ ↓ ↙
Java Project
↓
Write Java Code
↓
Compile
↓
JVM
↓
Run Program
Once this setup is complete, you have everything needed to begin learning Java and developing Java applications.
FAQs
Do I need JDK or JRE to learn Java?
You should install a JDK because you need the Java compiler and development tools to create Java programs.
Do I need to install both JDK and JRE?
Normally, you do not need to install a separate JRE for modern Java development. Installing a suitable JDK provides the development tools and runtime capabilities you need.
Is JAVA_HOME mandatory?
Not every Java application requires JAVA_HOME. However, many development tools and build systems use it, so configuring it can make your Java environment easier to manage.
Is PATH mandatory for Java?
You can run Java without a global PATH configuration by specifying the complete path to the Java executable. However, adding the JDK’s bin directory to PATH makes commands such as java and javac available directly from the terminal.
Which IDE should a beginner use?
IntelliJ IDEA, Eclipse, and VS Code can all be used to learn Java. The important thing is to understand Java itself rather than becoming dependent on a particular IDE.
Can I use VS Code instead of IntelliJ IDEA?
Yes. With the appropriate Java extensions and a properly installed JDK, VS Code can be used for Java development, including debugging, testing, Maven, and Gradle projects