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.
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.