Search code examples
javajvmjavac

If I compile java with javac do I need JVM?


I recently learned about how Java uses the JVM to make itself platform independent and I often write code and compile it with the javac command in terminal (Mac OS X). So my question is whether javac compiles it for JVM or if it is compiled directly to machine code? which would make it platform dependent.


Solution

  • The java compiler (javac) produces bytecode from source code. This bytecode is the instruction set of the JVM. It is run on the JVM so whilst the bytecode is platform independent, the JVM is not.