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.
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:
- Install Java (JDK) on Windows / macOS / Linux.
- Choose a simple editor or IDE.
- Write, compile, and run your first Java program (
HelloWorld). - Fix common setup problems.
- 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)
- Download an OpenJDK distribution (Oracle JDK, OpenJDK builds — Adoptium Temurin, Azul Zulu, etc.).
- Run the installer and follow instructions.
- Add the JDK
bindirectory to yourPATH(some installers do this automatically). - Optionally set
JAVA_HOMEto the JDK root.
Troubleshooting tips (Windows)
- If
javacnot found: open a new Command Prompt (or PowerShell) after install. If still not found, manually addC:\Program Files\Java\<jdk-version>\bintoEnvironment Variables → Path. - To set
JAVA_HOMEpermanently 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 updatesudo apt install openjdk-17-jdk(replace17with the version you prefer)- Verify with
java -versionandjavac -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 -versionExpected: 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-firstCreate 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
mainmethod with the exact signaturepublic static void main(String[] args). - The filename must match the
public classname:HelloWorld.java→public class HelloWorld.
5) Compile and run
From the java-first directory:
Compile:
javac HelloWorld.javaThis creates a HelloWorld.class file (bytecode). Run:
java HelloWorldOutput:
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 JDKbinfolder to your PATH, then open a new Command Prompt.Error: Could not find or load main class HelloWorld
-> Make sure you runjava HelloWorldfrom the directory containingHelloWorld.class. Do not include.classor.javain thejavacommand.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 -versionandjavac -versionmismatch), you may have multiple JDKs installed. Fix PATH andJAVA_HOMEto point to the intended JDK.
7) Small expansions — try these right now
- Modify
HelloWorld.javato 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.javaMain.java
Compile both withjavac *.javaand runjava Main.
8) Exercises (homework)
- Exercise 1: Print the sum of two integers which are provided as command line arguments. Example:
java Sum 4 5should print9. Handle the case when not enough arguments are passed. - Exercise 2: Create a
Personclass with fieldsnameandage. Create aMainclass to instantiate aPersonand print details. - Exercise 3: Install IntelliJ IDEA Community and create a new Java project. Re-create
HelloWorldin 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.
0 Comments