What is Java, and what does "write once, run anywhere" mean?

5 minbeginnerjavabasicsjvm

Quick Answer

Java is a class-based, statically-typed, object-oriented language that compiles to platform-independent bytecode. "Write once, run anywhere" (WORA) means that same .class bytecode runs unmodified on any device with a compatible JVM, because the JVM (not the OS) is the actual execution target.

Detailed Answer

Java source (.java) is compiled by javac into bytecode (.class files) — an intermediate, platform-neutral instruction set. At runtime, a Java Virtual Machine (JVM) built for the host OS/CPU interprets or JIT-compiles that bytecode into native instructions.

Because the compiler targets the JVM instead of a specific CPU/OS, the same .class file (or JAR) can run unmodified on Windows, Linux, macOS, or embedded devices — as long as a compatible JVM is installed there. This is "Write Once, Run Anywhere" (WORA).

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

Compile once with javac Hello.java, and the resulting Hello.class runs identically via java Hello on any platform with a JVM — no recompilation needed. The trade-off is a layer of indirection (the JVM itself), which historically cost some performance versus native-compiled languages, though modern JIT compilation closes most of that gap.

Related Resources