What happens between writing Java code and running it?
Options
javacmakes.classbytecode;javaruns it on the JVM (Correct option)- The browser reads the
.javafile and runs it directly - The code is converted into JavaScript and executed there
- Nothing: the CPU runs the
.javatext 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:
- You write source code in plain text files ending in
.java. - The compiler
javacturns them into.classfiles. They contain bytecode, the machine language of the Java Virtual Machine, not code for your CPU. - The
javatool 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 bytecodeRemember
.java → javac → .class (bytecode) → JVM runs it.