There's a question on StackOverflow about the comparison between Java and Python, and there are questions about why Java's runtime is called a JVM, and Python is called interpreter.
This problem is estimated not many people think, first look at Wikipedia to see the definition of virtual machine.
There are 2 definitions of virtual machines, one is a VMware-like system virtual machine, and the other is a virtual machine called a program virtual machine, such as JVM,CLR, which is the most common virtual machine.
A program virtual machine is also known as a managed runtime environment, and running this VM is like a process in a normal OS. When this process starts, the virtual machine is started and the virtual machine is destroyed when the process is destroyed. The purpose of using virtual machines is to provide a platform-independent programming environment.
The execution engine in the JVM can only handle compiled Java bytecode, and the bytecode processing engine actually contains a bytecode interpreter and a JIT compiler (which differs greatly from the JIT in. NET CLR), and the interpreter executes byte-code instructions one by one, with a slightly slower speed. The JIT compiler caches hot-spot code compilation and therefore performs faster.
The concept of an interpreter is simple, it can translate code, run it, do not need to be compiled, the interpreter in the JVM is formal, and the JVM interprets the bytecode. There are 3 ways the interpreter runs the program:
Run the Advanced programming language directly (such as the Shell's built-in interpreter)
Convert the high-level programming language code to some efficient bytecode (bytecode) and run these byte codes
Compiles the high-level language to the compiler contained by the interpreter and instructs the processor to run the compiled program (for example: JIT)
Where Python's interpreter is the second, Python code will compile the Python code into bytecode when it is first run, and if it does, it will save the bytecode to the. pyc file so that it will not compile the code the next time it is started, but simply explain the running bytecode. In fact, this mechanism is blurring the line between the interpreter and the compiler, or blurring the boundaries between interpreted and compiled languages.
Through the concept of the JVM and the interpreter, it seems that it is still not clear why the JVM is called a virtual machine, the JVM is running bytecode, it may be interpreted directly or can be compiled into the target language, the interpreter in Python will pre-compile Python code into bytecode, and then explain the execution. So what's the difference?
Many people participated in the discussion, respectively, from different angles to explain the difference.
Some people think that the virtual machine is not language-independent, for example, the JVM, in addition to Java, scala,clojure, even python with the help of Jython tools, can also run on the JVM, and did not hear any language can have the Python interpreter interpretation of execution, in addition to Python.
There are also people from the language type, Java is a static type of language, and Python is a dynamic language. This allows the Java bytecode to be interpreted and executed as a machine instruction. Python is a lot more complicated, and while it allows programmers to not focus on the types of variables, the interpreter has to infer the data type, which in some way affects performance.
There is also a view that the interpreter is a legacy term, and that the boundaries of virtual machines and interpreters in modern languages are blurred or even nonexistent.
In fact, the author in the "Learning Python" book, see the author of the Python interpreter called PVM, based on this fact, I more agree that the difference between the interpreter and the virtual machine is getting smaller, already I have you, you have my point. Independent segmentation, it may be possible to distinguish between these steps is the interpreter behavior, these steps are the behavior of the virtual machine, but as a whole, the difference is not so obvious.
This article is from "a blog" blog, make sure to keep this source http://cnn237111.blog.51cto.com/2359144/1616091
What is the Java Runtime Environment called a virtual machine, Python can only be called an interpreter