🧰 Java Basics to Intermediate
Estimated reading: 3 minutes 283 views

Java Get Started – How to Install, Setup & Run Your First Java Program


Introduction – Get Up and Running with Java in Minutes

You’ve learned what Java is. Now it’s time to write and run your first Java program! This guide walks you through the entire Java setup process — from downloading the JDK to compiling and executing your first program.

Whether you’re on Windows, macOS, or Linux, this step-by-step tutorial ensures you’ll be ready to start coding in Java — no prior experience needed!

By the end of this guide, you’ll be able to:

  • Download and install the Java JDK
  • Set up JAVA_HOME and PATH
  • Use a code editor or IDE to write Java code
  • Compile and run a basic Java program

Step 1: Download and Install Java JDK

Java programs are written using the Java Development Kit (JDK), which includes:

  • Java Compiler (javac)
  • Java Virtual Machine (JVM)
  • Java Runtime Environment (JRE)
  • Development tools and libraries

Where to Download:

Visit: https://www.oracle.com/java/technologies/javase-downloads.html

Alternative OpenJDK providers:

  • AdoptOpenJDK (Eclipse Temurin)
  • Amazon Corretto
  • Azul Zulu

Tip: Choose the latest LTS version like Java 17 or Java 21 for best stability.


Step 2: Install and Configure Environment Variables

After installation, you need to configure JAVA_HOME and update your system’s PATH.

For Windows:

  1. Search “Environment Variables”
  2. Add JAVA_HOME → Path to your JDK folder (C:\Program Files\Java\jdk-XX)
  3. Edit PATH → Add %JAVA_HOME%\bin

For macOS/Linux:

Add this to your terminal profile (.bashrc, .zshrc, or .bash_profile):

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-XX.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH

Check Installation:

java -version
javac -version

Expected output:

java version "21.0.1"
javac 21.0.1

Step 3: Write Your First Java Program

You can use any editor like:

  • Visual Studio Code
  • IntelliJ IDEA
  • Eclipse
  • Even Notepad or terminal editors

Create a File: HelloWorld.java

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Welcome to Java!");
    }
}

Line-by-Line Explanation:

  • public class HelloWorld — Defines the class
  • public static void main — Entry point of execution
  • System.out.println(...) — Outputs text to console

🏃 Step 4: Compile and Run Java Code

Compile:

javac HelloWorld.java

This creates a HelloWorld.class file (bytecode).

Run:

java HelloWorld

Output:

Welcome to Java!

Congratulations! You’ve just run your first Java program.


Optional: Set Up Java in an IDE

Using an IDE simplifies development with syntax highlighting, auto-complete, and integrated terminal.

Recommended Java IDEs:

IDEFeatures
IntelliJ IDEASmart refactoring, built-in debugger, Gradle/Maven integration
EclipsePopular for enterprise Java, plugin-rich
VS CodeLightweight, Java extensions via Marketplace

Tip: Use IntelliJ IDEA Community Edition for a powerful, free experience.


Summary – Java Get Started

Here’s what you’ve accomplished:

  • Installed Java JDK
  • Set environment variables (JAVA_HOME, PATH)
  • Wrote a Java program
  • Compiled and ran it from the terminal

Now you’re ready to explore Java’s syntax, control structures, and object-oriented features.


FAQs – Java Get Started

What is the difference between JDK and JRE?

  • JDK (Java Development Kit): For writing and compiling Java apps
  • JRE (Java Runtime Environment): For running already compiled Java apps

Do I need to set JAVA_HOME?

Yes, it’s required for many tools (like Maven, Gradle, IDEs) and scripts that depend on Java.

Can I install multiple Java versions?

Yes, use tools like jEnv (macOS/Linux) or SDKMAN to manage them.

Which Java version should I use in 2025?

Java 17 or Java 21 (both LTS versions) are recommended for stability and long-term support.


Share Now :
Share

Java Get Started

Or Copy Link

CONTENTS
Scroll to Top