Does Java produce object code or byte code?

前端 未结 5 2061
南笙
南笙 2020-12-19 07:04

It\'s my understanding that the Java compiler produces \"byte code\", not \"object code\". First of all, is this correct?

Also, that\'s just what my book says, I was

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-19 07:44

    C object code is in a form that only the OS on which it was compiled can interpret.

    C code -> C compiler(e.g. gcc) -> object code -> os

    The C compiler outputs object code for the OS that it was written for. If you want your C code to run on another machine, you have to recompile it.
    C code compiled on Windows won't run on linux without recompiling.

    Java code-> Java compiler(javac) -> byte code -> jvm

    The Java compiler puts out byte code that runs on its JVM. All the idiosyncracies of the OS are pushed down into the JVM, hidden from the Java code. So as long as your OS has a JVM, you can run Java bytecode on it without recompiling. Java code compiled on Windows can run on any other OS with the same version of JVM.

    Also refer difference between object code and byte code

提交回复
热议问题