what java actually is
the language, the JDK, the JVM, and why they're three different things.
- chapter
- chapter 01.01
- reading time
- 8 min read
"java" is three things wearing one name: the language (what you type), the JVM (a program that runs compiled java on any machine) and the JDK (the JVM plus the tools to build programs for it).
you write .java, javac turns it into bytecode, and the JVM runs that bytecode on whatever OS it's sitting on.
the picture
"install java". "java is slow". "we're still on java 17". three sentences, three different things called java. kinda confusing, so let's pull them apart.
think of sheet music. you compose a song (java source). a transcriber writes it down as sheet music (javac → bytecode). any musician who can read sheet music can play it, on whatever instrument they have (a JVM, on whatever OS). the sheet music never changes between performances. the musician does.
one native program (libjvm) that loads .class files, checks them, runs the bytecode in an interpreter, compiles the hot parts to machine code with the JIT, and cleans up dead objects with the GC.
- java
- the language: what
class,intandformean. written down in the java language specification (the JLS). - JVM
- java virtual machine. an actual program (mostly C++) that runs bytecode. it has its own spec, the JVMS, and it has never seen a line of java syntax.
- JDK
- java development kit. the JVM, the standard library and the tools (
javac,jshell,jar...). this is what you install. - JRE
- java runtime environment: the JDK without the dev tools. oracle stopped shipping a separate one with java 11 (some vendors still build them). today you install a JDK, or ship a trimmed runtime made with
jlink. - OpenJDK
- the open-source project where the JDK is built. temurin, corretto, oracle's JDK: all builds of the same code. which one to pick is in getting a JDK.
write once, run anywhere
here's the trick. javac does not compile your code to x86 or arm machine code. it compiles to bytecode, the instruction set of a CPU that doesn't exist. then every OS gets its own JVM, which knows how to run that made-up CPU on the real one underneath.
a mac JDK has a libjvm.dylib built for apple silicon. the .class didn't change. only the JVM did.
.class file is byte-for-byte identical; the JVM is the part you download per platform. kotlin, scala and clojure live here too: their compilers emit the same bytecode, so the JVM can't tell the difference.you can see the bytecode's fingerprint yourself. every class file on earth starts with the same four bytes:
$ javac Main.java
$ xxd Main.class | head -1
00000000: cafe babe 0000 0045 001d 0a00 0200 0307 .......E........CAFEBABE is the magic number (an old joke from the people who designed the format). 0x45 is 69, the class file version for java 25. we'll take one apart in compile and run.
compiled or interpreted? both
people argue about this one. the honest answer is that java gets compiled twice.
hover a stage.
that second compile is why java programs speed up after a few seconds of running (people call it warm-up), and why "java is slow" is mostly a story about startup. once the JIT has had a look, hot code runs as native machine code, sometimes better tuned than what a C compiler would guess ahead of time, because the JIT knows what your program actually does. the full story is in the interpreter and the JIT.
one language, many versions
a new java ships every march and every september, like a train that leaves on schedule whether your feature is on it or not. every two years, one release is LTS (long-term support): vendors keep patching it for years, so that's what most companies run. 17, 21 and now 25.
- →void main() + IO.println
- →flexible constructor bodies
- →import module
- →compact object headers
old versions called themselves 1.something: java 8 is "1.8" and its java -version still prints 1.8.0_.... from 9 on it's just the number. every release in detail lives in java 8 → 27.
who actually owns java+
Sun Microsystems made it (James Gosling's team, 1.0 shipped in january 1996). Sun open-sourced the JDK as OpenJDK in 2006-2007, under the GPL with the "classpath exception", which is what lets you ship closed-source programs on top of it. Oracle bought Sun in 2010 and still leads the project, but changes go through public proposals called JEPs (JDK enhancement proposals), and Red Hat, Amazon, Microsoft, Google, SAP and others work on the same code. "java" is an Oracle trademark, which is why every other vendor calls its build something else: temurin, corretto, zulu.
- the language is what you type. the JVM is what runs it. the JDK is the box both come in.
javaccompiles to bytecode, not machine code. the JVM's JIT makes machine code while your program runs.- one
.classruns on every OS. the JVM is the part that's different per platform. - a new java every six months, an LTS every two years. learn on the latest LTS: 25.