Source code, bytecode and the JVM
What you will learn
Java source code is human-readable text. A Java compiler translates it into class files containing JVM bytecode and related information. The Java Virtual Machine (JVM) executes that representation, interpreting or compiling instructions as appropriate.
public class Main { public static void main(String[] args) { System.out.println(6 * 5); }}Expected output:
30The multiplication is expressed in source code; the compiler produces a class file implementing its behavior.
How it works
The typical workflow is Main.java → javac → Main.class → java Main. A compatible runtime and required libraries are still necessary on the target machine. Bytecode is not the same as native machine instructions, and the JVM specification does not require a particular optimization strategy.
public class Main { public static void main(String[] args) { System.out.println("Checking stock"); System.out.println(15 - 4); }}Expected output:
Checking stock11The main method executes these two statements in order.
Common mistakes
Do not assume a class file from a newer JDK runs on every older JVM. Compile with an appropriate --release target and test against that runtime.
Try it yourself
Draw the four-stage workflow and identify where a source edit must be recompiled.
These are local Java practice tasks, not automatically graded ByteMind exercises. Use a patched JDK; no network or third-party dependency is needed.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Source code, bytecode and the JVM — knowledge check
Check your understanding of source code, bytecode and the jvm.
Which artifact does javac normally produce?
What is needed to run a class file on another machine?