Java β Overview
Before you start: no prior programming experience is required, though comfort with basic programming logic (variables, loops, if/else in any language) helps β Java's syntax is introduced from scratch below.
Why This Exists (The Hook)
A C program compiled on Windows won't run on Linux without recompiling from source for that specific machine β the compiled output is tied to one operating system's hardware conventions. Java exists specifically to break that dependency: compile once to an intermediate form (bytecode), and any machine with a JVM installed β Windows, Linux, macOS β runs that exact same compiled file unchanged. "Write once, run anywhere" isn't marketing language; it's a direct description of what the JVM layer mechanically does.
Analogy β Think of Java bytecode like a universal power adapter, not a country-specific plug. A device with a fixed US plug simply doesn't work in a UK socket β you'd need to rebuild the device itself for each country. A universal adapter (the JVM) lets the exact same device (your compiled bytecode) plug into any country's socket, because the adapter β not the device β handles the platform-specific translation. javac compiles your code into that universal "plug" once; each platform's own JVM is the adapter that makes it work there.
Try it (2 minutes) β Reason through why javac HelloWorld.java and java HelloWorld are two separate commands instead of one, without looking anything up: javac (the compiler) translates your .java source into .class bytecode β a file no operating system can execute directly. java (invoked via the JVM) is what actually reads and runs that bytecode. If Java collapsed both into a single "compile and run directly to native machine code" step, the way a language like C does, what would happen to the promise that the same compiled output runs unchanged on Windows, Linux, and macOS?
What is Java?
Java is a class-based, object-oriented programming language designed around "write once, run anywhere" (WORA). Java source code compiles to an intermediate form called bytecode, which runs on the Java Virtual Machine (JVM) rather than directly on the underlying hardware β that's what makes the same compiled .class file run unchanged on Windows, Linux, or macOS, as long as each has a JVM installed.
Released in 1995 by Sun Microsystems (now owned by Oracle), Java remains one of the most widely used languages in the world β enterprise backend systems, Android apps, and large parts of the big-data ecosystem (Hadoop, Spark) are built on it.
JDK vs. JRE vs. JVM β A Distinction Worth Getting Right
These three terms get confused constantly, and interviewers ask about the distinction specifically because it reveals whether you actually understand the Java toolchain, not just the language:
| Term | What It Is |
|---|
|---|---|
| **JVM (Java Virtual Machine)** | The runtime engine that executes bytecode. Platform-specific β a Windows JVM and a Linux JVM are different programs, but both run the same `.class` files. |
|---|---|
| JRE (Java Runtime Environment) | JVM + the standard class libraries needed to run Java programs. If you only need to run compiled Java programs, JRE is enough. |
| JDK (Java Development Kit) | JRE + the compiler (javac), debugger, and other tools needed to write and build Java programs. If you're developing, you need the JDK. |
In practice today, most installations just ship the JDK (which includes everything), so this distinction matters more for understanding what each tool does than for choosing what to install.
Why Learn Java?
Java Versions
| Version | Year | Key Features |
|---|
|---|---|---|
| Java 8 LTS | 2014 | Lambda expressions, Stream API, `Optional` |
|---|---|---|
| Java 11 LTS | 2018 | HTTP client, local variable type inference (var) |
| Java 17 LTS | 2021 | Records, sealed classes, pattern matching for switch |
| Java 21 LTS | 2023 | Virtual threads, sequenced collections |
LTS (Long-Term Support) versions β 8, 11, 17, 21 β receive updates and security patches for years after release, which is why production systems standardize on them rather than every new release. For new learning and new projects, Java 17 or 21 is the reasonable default.
Install Java
Hello World, With the Compile-Then-Run Cycle Made Explicit
This two-step compile-then-run cycle is worth internalizing early: javac never produces something directly executable by your OS β it produces bytecode, which only the JVM (invoked via the java command) can run. This is the mechanical reason Java code is portable across operating systems.

