You do not have to take this on faith, because you can watch every step.
// step 1: compile, and see the bytecode file appear
javac HelloWorld.javals// step 2: inspect the version bytes the JVM will check
javap -verbose HelloWorld.class | head -5// step 3: run it
java HelloWorld// step 4: confirm it really is a class file
file HelloWorld.class
Step 2 is the interesting one. It prints the major version number, so you can see the exact number an older JVM would be checking. If you want the full chain of what javac and java actually are, we explain the difference in the JDK components and installation guide.
Frequently Asked Questions
Is Java compiled or interpreted?
Both, and that is not a contradiction. javac compiles your source into bytecode ahead of time, then the JVM interprets that bytecode and progressively JIT-compiles the hot parts into native code while the program runs.
What is the difference between bytecode and machine code?
Bytecode is an intermediate instruction set that any JVM can run, so one build works on every platform. Machine code is specific to one processor family. Java lets the JVM do that final translation on the machine it is actually running on.
Why is my Java program slow on the first run?
Because the JVM is still interpreting and has not decided which methods are hot. Once a method crosses the JIT threshold it is compiled to native code and reused. This warm-up is normal and is why benchmarks need a warm-up phase.
Does the JVM verify bytecode for safety?
Yes. The verifier checks types, stack depth and branch targets before a class is allowed to run, so malformed or hand-crafted class files are rejected rather than being allowed to corrupt memory. It is a real protection, though it is not a full security sandbox.
What does one class file per class mean in practice?
An inner class inside Outer produces a separate class file, and its name contains the outer class name with a dollar sign, such as Outer$Inner.class. Both live inside the file named after the outer class.
Can I skip javac and just run the file?
Since Java 11 you can launch a single source file directly with java HelloWorld.java, and the JVM compiles it in memory first. It is a convenient way to try things quickly, but for anything you ship you still want a proper build step.