1.3.2 Java Program operating mechanism and JVM

Source: Internet
Author: User

The Java language is special, a program written by the Java language needs to be compiled, but this compilation step does not generate a platform-specific machine code, but instead generates a platform-independent bytecode (that is, the *.class file). Of course, this bytecode is not executable and must be interpreted using the Java interpreter. Therefore, we can assume that: the Java language is both a compiled language and an interpreted language. In other words, the Java language is neither a purely compiled language nor a purely interpretive language. The execution of a Java program must be compiled first and then interpreted in two steps. As shown in 1.1.

In the Java language, the Java Virtual Machine is responsible for interpreting the execution of bytecode files, both the JVM (Java Vsan). The JVM is a virtual machine that can run Java bytecode files. The JVM on all platforms provides the compiler with the same programming interface, and the compiler only needs to target the virtual machine, generate the code that the virtual machine understands, then interpret the execution by the virtual machines, and in some implementations of the virtual machine, the virtual machine code is converted to the machine code of the specific system, thus improving execution efficiency.

When compiling Java programs using the Java compiler, platform-independent bytecode is generated, which is not targeted at any specific platform and is intended for the JVM only. The JVMs on different platforms are different, but they all provide the same interface. The JVM is a key part of the Java program's cross-platform, and as long as the corresponding virtual machines are implemented for different platforms, the compiled Java bytecode can be run on that platform. Obviously, the same bytecode program needs to run on a different platform, which is almost "impossible" and can only be achieved by means of an intermediate converter, the JVM being the converter.

The JVM is an abstract computer that, like the actual computer, has instruction sets and uses different storage areas. It is responsible for executing instructions and managing data, memory, and registers.

Hint: the role of the JVM is very easy to understand, as we have two different pens, but need to put the same cap on two different pens, only to provide a translator for the two pens, the converter up the same interface to adapt to the same cap, down the interface is different, Used to accommodate two different pens. In this analogy, we can roughly understand that two different pens are different operating systems, while the same cap is the Java bytecode program, and the converter role corresponds to the JVM. Similarly, we can assume that the JVM is divided into up and down two parts, and that the JVM on all platforms is exactly the same interface that is provided to the Java bytecode program, but the interfaces that adapt down to different platforms differ.

The Java Virtual Machine specification developed by Sun has technically defined the JVM's uniform standards, specifically defining the following details of the JVM:

    • Instruction Set

    • Register

    • The format of the class file

    • Stack

    • Garbage collection Heap

    • Storage area

The purpose of these specifications is to provide a unified standard for the eventual implementation of the platform-agnostic nature of Java programs.


1.3.2 Java Program operating mechanism and JVM

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.