Card 01/ 06

ConceptDifficulty: Beginner1 min

Why Your .java File Is Not a Program Yet

You save Hello.java, double-click it, and nothing happens. The file is text. Your operating system does not know what to do with it, and your processor knows even less.

Every language that is not machine code has to be translated before anything can run it. Most languages translate once, straight into instructions for the processor in front of them. Java translates twice, and the second half of its name is the reason.

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

The first translation turns that text into bytecode: a compact instruction set that no real processor understands. The second happens while your program is running. A piece of software called the Java Virtual Machine — the JVM — reads the bytecode and issues instructions the processor underneath it does understand.

Source text becomes bytecode, and the JVM turns bytecode into instructions

So a Java mistake reaches you at one of two completely different moments. A misspelled keyword is caught by the first translation and there is no program at all. A missing file is discovered by the second, minutes into a run, with output already on the screen.