Java Environment Setup – Step-by-Step Guide
Are you ready to write your first Java program? Before jumping into the code, the first step is to set up your Java development environment. This tutorial will walk you through the process of downloading, installing, and configuring everything you need to start coding in Java.
Whether you’re on Windows, macOS, or Linux, we’ve got you covered!
What You Need to Run Java
To develop and run Java programs, you’ll need two main tools:
JDK (Java Development Kit) – Contains the Java compiler (
javac
) and other tools to develop Java applications.IDE (Integrated Development Environment) – A text editor designed for writing code. Popular IDEs for Java include IntelliJ IDEA, Eclipse, and VS Code.
Step 1: Download and Install the JDK
Download JDK
Oracle JDK: https://www.oracle.com/java/technologies/javase-downloads.html
OpenJDK (free and open source): https://jdk.java.net
Choose the version that matches your operating system.
Install JDK (Windows/macOS/Linux)
Windows: Run the
.exe
installer and follow the prompts.macOS: Download and install the
.dmg
file.Linux: Use your package manager (e.g.,
sudo apt install openjdk-17-jdk
on Ubuntu).
Step 2: Set JAVA_HOME and PATH (Windows)
After installing JDK, you should set up environment variables so that Java can be accessed from any terminal or command prompt.
Setting JAVA_HOME and PATH (Windows):
Open System Properties > Advanced > Environment Variables
Click New under “System Variables”
Variable name:
JAVA_HOME
Variable value: Path to your JDK folder (e.g.,
C:\Program Files\Java\jdk-17
)
Select the
Path
variable > Click EditAdd:
%JAVA_HOME%\bin
Verify Installation
Open Command Prompt and type:
java -version
javac -versionYou should see the installed Java version displayed.
Step 3: Choose and Install an IDE
Here are some popular Java IDEs:
IDE | Description | Download Link |
---|---|---|
IntelliJ IDEA | Beginner-friendly, rich features | jetbrains.com/idea |
Eclipse | Popular in enterprise environments | eclipse.org |
VS Code | Lightweight, needs Java extension | code.visualstudio.com |
Choose one and install it like any other software.
Step 4: Write and Run Your First Java Program
Here’s a simple Java program you can try:
HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, Java!");
}
}
To Compile and Run (Using Terminal):
Save as
HelloWorld.java
Open terminal or CMD and navigate to the file’s folder
Compile:
javac HelloWorld.java
Run:
java HelloWorld
Output:
Hello, Java!
Bonus: Useful Java CLI Tools
javac
– Compiles.java
filesjava
– Runs compiled.class
filesjavadoc
– Generates documentationjar
– Packages Java files into a.jar
archive
Conclusion
Setting up the Java environment is a one-time process, but it’s the foundation of your development journey. Once it’s done, you’re ready to write, compile, and run Java programs effortlessly.