Search code examples
javajvmbytecode

What exactly does the JVM do?


I'm little confused. Does the JVM generate the bytecode? Or does it just load the compiled .class files (bytecode) into memory? Or is the JVM just specifications to run the bytecode in a platform-independent way?


Solution

  • The Java compiler (javac) turns your human-readable code into bytecode, which is then running in a JVM.

    From the oracle docs:

    A program has to be converted to a form the Java VM can understand so any computer with a Java VM can interpret and run the program. Compiling a Java program means taking the programmer-readable text in your program file (also called source code) and converting it to bytecodes, which are platform-independent instructions for the Java VM.