Repaso
Español
Java CoreFoundationsJV-42

What happens between writing Java code and running it?

Options

  1. javac makes .class bytecode; java runs it on the JVM (Correct option)
  2. The browser reads the .java file and runs it directly
  3. The code is converted into JavaScript and executed there
  4. Nothing: the CPU runs the .java text exactly as written

Answer

javac compiles the .java files into .class files of bytecode, then the java launcher runs them on the JVM

Why

The Java tutorial describes the steps:

  1. You write source code in plain text files ending in .java.
  2. The compiler javac turns them into .class files. They contain bytecode, the machine language of the Java Virtual Machine, not code for your CPU.
  3. The java tool runs your application with an instance of the JVM.

Maven and your IDE do these steps for you, but this is what happens underneath.

javac Hello.java   # creates Hello.class (bytecode)
java Hello         # JVM runs the bytecode

Remember

.java → javac → .class (bytecode) → JVM runs it.

Key terms

Practice this question in Repaso