Camp 1 · Schritt 3 von 13
Compiling and running
javac, bytecode, and the JVM — the two-step journey every Java program takes.
10 Min.+50 XPAuf Englisch angezeigt — Übersetzung ist unterwegs
Python runs your source directly; Java takes two deliberate steps. Knowing them demystifies every error message you'll ever see.
The pipeline
Main.java ──(javac)──▶ Main.class ──(java)──▶ output
source compiler bytecode JVM runs itOn your own machine it looks like:
javac Main.java # compile: produces Main.class (bytecode)
java Main # run: JVM executes the bytecodejavacis the compiler: it checks your entire program and, only if everything is valid, emits.classbytecode files.javastarts the JVM, which executes bytecode — translating it to fast machine code on the fly.
(Our playgrounds do both steps for you in the cloud — the pause before output is compilation.)
Two kinds of errors, two moments
JavaCloud-Run
Break it two ways and observe:
- Delete the
;afterint lessons = 13→ compile-time error. The compiler rejects it; nothing runs at all. - Change the print to
System.out.println(10 / (lessons - 13));→ compiles fine, then runtime error (ArithmeticException: / by zero) while running.
Compile errors are grammar; runtime errors are logic. Java's design pushes as many mistakes as possible into the first, cheaper category.
Checkpoint
What does javac produce from Main.java?
Checkpoint
A division-by-zero in otherwise valid code is discovered…