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:

  1. JDK (Java Development Kit) – Contains the Java compiler (javac) and other tools to develop Java applications.

  2. 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

 
Visit the official Oracle website or OpenJDK site to download the latest JDK version.

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):

 
  1. Open System Properties > Advanced > Environment Variables

  2. Click New under “System Variables”

    • Variable name: JAVA_HOME

    • Variable value: Path to your JDK folder (e.g., C:\Program Files\Java\jdk-17)

  3. Select the Path variable > Click Edit

  4. Add:
    %JAVA_HOME%\bin

    Verify Installation

     

    Open Command Prompt and type:

    java -version
    javac -version

    You should see the installed Java version displayed.

Step 3: Choose and Install an IDE

 

Here are some popular Java IDEs:

IDEDescriptionDownload Link
IntelliJ IDEABeginner-friendly, rich featuresjetbrains.com/idea
EclipsePopular in enterprise environmentseclipse.org
VS CodeLightweight, needs Java extensioncode.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):

 
  1. Save as HelloWorld.java

  2. Open terminal or CMD and navigate to the file’s folder

  3. Compile:

    javac HelloWorld.java
  4. Run:

    java HelloWorld

Output:

Hello, Java!

Bonus: Useful Java CLI Tools

 
  • javac – Compiles .java files

  • java – Runs compiled .class files

  • javadoc – Generates documentation

  • jar – 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.

Scroll to Top