Java / JVM Architecture (Java21) Interview questions
What is bytecode in Java?
Bytecode is the platform-independent instruction set that the javac compiler produces from Java source code and stores in .class files.
It is not tied to any specific CPU - instead, any JVM that implements the JVM specification can load and run it, which is what makes a compiled class portable across operating systems.
// Source: Hello.java public class Hello { public static void main(String[] args) { System.out.println("Hi"); } } // javac Hello.java produces Hello.class // javap -c Hello shows bytecode instructions such as: // getstatic #2 // java/lang/System.out // ldc #3 // "Hi" // invokevirtual #4 // println // return
The JVM's Interpreter or JIT compiler is what turns these bytecode instructions into actual CPU-level machine instructions at run time.
More Related questions...