What Java Is & How to Get Started ?(Install + Hello World)

A friendly, no-fluff first step into Java — install the JDK, pick an editor, run your first program, and know how to fix the common setup issues.

Press enter or click to view image in full size
Photo by Caspar Camille Rubin on Unsplash

Why learn Java?

Java is one of the most widely used programming languages: backend services, Android apps, large enterprise systems, and many tools use it. It’s object-oriented, statically typed, and has a strong ecosystem — which makes it a great first serious language and also future-proof for many jobs.

This is the first post in a hands-on series. Today we’ll:

  1. Install Java (JDK) on Windows / macOS / Linux.
  2. Choose a simple editor or IDE.
  3. Write, compile, and run your first Java program (HelloWorld).
  4. Fix common setup problems.
  5. Give exercises and next steps.

Prerequisites

  • A desktop or laptop (Windows, macOS, or Linux).
  • Basic comfort with the command line (I’ll show exact commands).

1) Install the Java Development Kit (JDK)

You need the JDK (Java Development Kit) — it contains the compiler (javac) and the runtime (java).

Windows (summary)

  1. Download an OpenJDK distribution (Oracle JDK, OpenJDK builds — Adoptium Temurin, Azul Zulu, etc.).
  2. Run the installer and follow instructions.
  3. Add the JDK bin directory to your PATH (some installers do this automatically).
  4. Optionally set JAVA_HOME to the JDK root.

Troubleshooting tips (Windows)

  • If javac not found: open a new Command Prompt (or PowerShell) after install. If still not found, manually add C:\Program Files\Java\<jdk-version>\bin to Environment Variables → Path.
  • To set JAVA_HOME permanently in PowerShell:
    setx -m JAVA_HOME "C:\Program Files\Java\jdk-17.0.x"

macOS (summary)

Option A (recommended for developers): use Homebrew:

brew install openjdk
After install, follow brew’s post-install instructions (it usually tells you what export commands to run).

Option B: download installer from an OpenJDK distribution and run it.

To set JAVA_HOME temporarily:

  • export JAVA_HOME=$(/usr/libexec/java_home)

To set it permanently, add that line to ~/.zshrc (or ~/.bash_profile) and restart terminal.

Linux (Ubuntu / Debian)

  • sudo apt update
  • sudo apt install openjdk-17-jdk (replace 17 with the version you prefer)
  • Verify with java -version and javac -version.

On other distros use your package manager (dnf, pacman, etc.) or download a tarball.

2) Verify installation

Open a terminal / command prompt and run:

java -version
javac -version

Expected: both commands print a Java version (e.g., openjdk version "17.0.x"). If javac prints “command not found”, your PATH is not set correctly.

3) Choose an editor / IDE

Start simple — you don’t need a heavy IDE for the first programs. Options:

  • VS Code (lightweight) + Java Extension Pack (good stepping stone).
  • IntelliJ IDEA Community Edition — excellent for Java, recommended when you move beyond basics.
  • Eclipse — mature and stable.
  • A plain text editor (Notepad++, Sublime, etc.) — OK for learning basics.

If you plan to follow this series and build real projects later, I recommend IntelliJ IDEA Community.

4) Your first Java program — HelloWorld

Create a directory for the exercise:

mkdir java-first
cd java-first

Create a file named HelloWorld.java with this content:

public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}

Why public class HelloWorld and main?

  • Every Java program runs starting from a main method with the exact signature public static void main(String[] args).
  • The filename must match the public class name: HelloWorld.java → public class HelloWorld.

5) Compile and run

From the java-first directory:

Compile:

javac HelloWorld.java

This creates a HelloWorld.class file (bytecode). Run:

java HelloWorld

Output:

Hello, world!

If you see that, congrats — your JDK and workflow are working!

6) Common errors & how to fix them

  • 'javac' is not recognized (Windows)
    -> Add the JDK bin folder to your PATH, then open a new Command Prompt.
  • Error: Could not find or load main class HelloWorld
    -> Make sure you run java HelloWorld from the directory containing HelloWorld.class. Do not include .class or .java in the java command.
  • class HelloWorld is public, should be declared in a file named HelloWorld.java
    -> Ensure the filename matches the public class name exactly (case-sensitive).
  • Wrong Java version issues
    -> If tools show different versions (e.g., java -version and javac -version mismatch), you may have multiple JDKs installed. Fix PATH and JAVA_HOME to point to the intended JDK.

7) Small expansions — try these right now

  1. Modify HelloWorld.java to print your name and the current year. Example:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, I'm Qayyum!");
System.out.println("Year: 2025");
}
}

2. Read a command line argument and print it:

public class HelloWorld {
public static void main(String[] args) {
if (args.length > 0) {
System.out.println("Argument 0: " + args[0]);
} else {
System.out.println("No arguments provided.");
}
}
}

Run with: java HelloWorld Welcome

3. Create two classes in the same folder:

  • Greeter.java
  • Main.java
    Compile both with javac *.java and run java Main.

8) Exercises (homework)

  • Exercise 1: Print the sum of two integers which are provided as command line arguments. Example: java Sum 4 5 should print 9. Handle the case when not enough arguments are passed.
  • Exercise 2: Create a Person class with fields name and age. Create a Main class to instantiate a Person and print details.
  • Exercise 3: Install IntelliJ IDEA Community and create a new Java project. Re-create HelloWorld in the IDE and run it.

9) Best practices for beginners

  • Keep files and classes named clearly and consistently.
  • Compile often — small incremental changes make debugging easier.
  • Learn the compiler and runtime error messages — they often tell you exactly what’s wrong.
  • Use an IDE once you start working with multiple files — it saves a lot of friction.

10) Summary

Today you:

  • Installed the JDK (or learned how to),
  • Wrote, compiled, and ran your first Java program,
  • Learned common setup fixes and starter exercises.

Post a Comment

0 Comments