Why are compiled Java class files smaller than C compiled files?

后端 未结 9 1499
被撕碎了的回忆
被撕碎了的回忆 2020-12-16 17:16

I would like to know why the .o file that we get from compiling a .c file that prints \"Hello, World!\" is larger than a Java .class file that also prints \"Hello, World!\"?

9条回答
  •  天命终不由人
    2020-12-16 17:52

    Java is compiled into a machine independent language. This means that after it is compiled it is then translated at run-time by the Java Virtual Machine (JVM). C is compiled to machine instructions and is therefore all of the binary for the program to run on the target machine.

    Because Java is compiled to a machine independent language, the specific details for a particular machine are handled by the JVM. (i.e. C has machine specific overhead)

    That is how I think about it anyway :-)

提交回复
热议问题