The operating mechanism of the Java language

Source: Internet
Author: User

The high-level computer programming language can be divided into compiled and interpreted languages according to the way its programs are executed.

A compiled language is a machine instruction that uses a specialized compiler to translate source code into computer recognition for a particular operating system at once. For example, C, C + +, etc. are compiled languages.

Explanatory language refers to the use of specialized interpreters, the source code is interpreted as a specific platform of the machine instructions, the interpretation of an execution sentence, similar to "simultaneous translation." For example, ASP, PHP, etc. are interpreted language.

Java is neither a compiled language nor an interpreted language, it is a combination of compiled and interpreted languages. The Java source program is first compiled into a platform-independent bytecode file (class file) using a common Java compiler, which is then interpreted by the Java Virtual Machine (JVM) for bytecode files.

Both compiled and interpreted languages have their own advantages and disadvantages, such as a compiled language will be compiled in the first execution of the program will be all the machine instructions corresponding to the current system platform, in the subsequent execution, run the results of the first compilation, reduce the number of compilations, improve the program running efficiency, However, the program corresponds to the system platform at the time of the first compilation, so the portability is relatively poor. While the interpretation of the language in each run of the program to interpret the source program as the current system platform corresponding to the machine instructions, so that a run must be interpreted and executed, inefficient operation, but strong portability.

The Java language combines the advantages of a compiled and interpreted language, and takes a compromise. That is, when the Java language first runs, it compiles the Java source program into a Java bytecode file, which is independent of the system platform and is a state between the source code and the machine instruction. In subsequent executions, an explanatory mechanism is taken to interpret the Java bytecode as a machine instruction corresponding to the system platform. This reduces the number of compile times, but also enhances the portability of the program, so it is called "one-time compilation, running in multiple places!" ”。

Note: Java bytecode is platform agnostic and can run on a variety of different system platforms, but requires different versions of the Java Virtual machine, and the Java Virtual machine for different system platforms is not the same.

JVM definition

The JVM (Java Virtual machine) means a Java VM. It is a virtual computer that can virtual a variety of computer functions on the actual computer. The JVM has its own complete hardware architecture, such as processors, stacks, and registers, as well as a corresponding instruction system.

JVM role

The JVM is an engine of Java bytecode execution that performs the necessary execution of Java programs, and optimizes Java bytecode to convert it into more efficient machine instructions. Programs written by programmers are ultimately executed on the JVM, and the load of classes in the JVM is implemented by the class loader (ClassLoader) and its subclasses. ClassLoader is an important system component of the Java runtime that is responsible for locating and loading class files at run time.

The JVM masks information related to the operating system platform, enabling Java programs to run without modification on multiple platforms by simply generating bytecode files (class files) that run on the JVM. Different platforms correspond to different JVMs, and when executing bytecode, the JVM is responsible for sending each byte code to be executed to the interpreter, which translates it into machine instructions for a particular platform environment and executes it. The most important feature of the Java language is that it runs across platforms, and the JVM is designed to support operating system-independent, cross-platform operations.

How the JVM Works

The JVM is at the bottom of the entire JDK and is responsible for interacting with the operating system, shielding the operating system environment, providing a complete Java runtime environment, and therefore also known as a virtual calculator. The operating system is loaded into the JVM through the Java.exe in the JDK, mainly through the following steps to complete.

1. Create the JVM loading environment and configuration.

2, loading Jvm.dll.

3, initialize the Jvm.dll.

4. Call the JNIEnv instance to load and process the class.

5, run the Java program.

The JVM is the most central part of the Java operating environment and is the most basic environment for running Java programs, and it is important to understand the concepts and operating mechanisms of the Java runtime.


"Reproduced use, please specify the source:http://blog.csdn.net/mahoking"

The operating mechanism of the Java language

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.