Java “Virtual Machine” vs. Python “Interpreter” parlance?

后端 未结 13 622
春和景丽
春和景丽 2020-11-29 14:45

It seems rare to read of a Python \"virtual machine\" while in Java \"virtual machine\" is used all the time.

Both interpret byte codes; why call one a virtual machi

13条回答
  •  無奈伤痛
    2020-11-29 15:10

    Python can interpret code without compiling it to bytecode. Java can't.

    Python is an interpreted language, as opposed to a compiled one, though the distinction can be blurry because of the presence of the bytecode compiler. This means that source files can be run directly without explicitly creating an executable which is then run.

    (from the documentation).

    In java, every single file has to be compiled to a .class file, which then runs on the JVM. On the contrary, python does that are imported by your main script, to help speed up subsequent uses of those files.

    However, in the typical case, most of the python (at least, CPython) code runs in an emulated stack machine, which has nearly identical instructions to those of the JVM, so there's no great difference.

    The real reason for the distiction however is because, from the beginning, java branded itself as "portable, executable bytecode" and python branded itself as dynamic, interpreted language with a REPL. Names stick!

提交回复
热议问题