Java Program operating mechanism

Source: Internet
Author: User


The operating mechanism of high-level language

computer High-level language according to the execution of programs can be divided into two types of compilation and interpretation .

Compiled language refers to the use of specialized compilers, for a specific platform, that is, the operating system to a high-level language source code translation into a machine code can be executed by the platform hardware, and packaged into the platform can be recognized by the executable program

format, this conversion process is called compiling, and the executable program generated by the compilation can be run independently of the development environment and on a specific platform .

After some programs have been compiled, it may also be necessary to connect to other compiled target code, that is, to assemble more than two target code templates to generate the final executable program, in this way to achieve low-level code reuse.

Because the compiled language is compiled into machine code one-time, it can run independently from the development environment and is usually more efficient, but because the compiled language program is compiled into machine code on a particular platform, compiling the generated

executables are often not portable to other platforms , and if porting is required, the source code must be copied to a specific platform, modified for a specific platform, or at least recompiled by a compiler on a specific platform.

Today's high-level languages such as c,c++,object-c,pascal are compiled languages.


An interpreted language is a language that uses a specialized interpreter to interpret a machine code on a per-line basis into a specific platform and execute it immediately.

interpreted languages generally do not compile and concatenate as a whole, and interpreted languages are equivalent to mixing compilation and interpretation processes together in a compiled language .

You can think of it this way: Every program that executes an interpreted language needs to be compiled once, so the program of the interpreted language is usually less efficient and can not run independently from the interpreter.

However, the interpreter language has an advantage, it is easy to cross-platform, only need to provide a specific platform of the interpreter , each specific platform on the interpreter is responsible for the source program is interpreted as a specific platform machine code instructions. Explanatory language can be easily

Implementation at the source program level, but it is code that sacrifices the execution efficiency of the program.

Now the Javascript,ruby,python, and other languages belong to the interpretive language.


Operating mechanism and JVM for Java programs

The Java language is special, programs written by the Java language need to be compiled steps, but this compilation step does not generate a specific platform machine code, but rather a platform-independent bytecode, that is, the *.class file .

Of course, This bytecode is not executable, and the Java interpreter must be used to interpret the execution .

It can be argued that the Java language is both a compiled language and an interpreted language, or that the Java language is neither a purely compiled language nor a purely interpretive language.

The Java program's execution must be compiled first and then explained in 2 steps .

Java source files, compiled with Javac compile-build *.class files, use Java to interpret the machine code that is interpreted as a specific platform by executing the preceding bytecode file.


The Java language is responsible for interpreting the Java virtual machine that executes the bytecode file, that is, Jvm,java Vsan. The JVM is a virtual machine that can run Java bytecode files. The JVM on all platforms provides the same programming to the compiler

interface, and the compiler only needs to target the virtual machine, generate the code that the virtual function understands, and then the virtual machine interprets the execution . In the implementation of some virtual machines, the virtual machine code is also converted to the machine code execution of a specific system, thus improving the

The efficiency of the line.


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.

JVMs are different on different platforms, but they all provide the same interface. The JVM is a key part of the Java program's cross-platform, as long as the corresponding virtual machines are implemented for different platforms, the compiled Java bytecode can be shipped on the platform .

line . Obviously, the same bytecode program needs to run on a different platform, which is almost impossible, and is only possible with the intermediate converter, which is the JVM.


The JVM is an abstract computer that, like the actual computer, has an instruction set and uses a different access area. It is responsible for executing instructions, as well as managing data, memory, and registers.

The Java Virtual Machine specification developed by Oracle technically defines the JVM's uniform standards, defining the following details of the JVM:

Instruction Set + Register + class file format + stack + garbage collection heap + storage.

Oracle has developed these specifications in order to provide a unified standard that ultimately implements the platform independence of Java programs.



Java program run mechanism

Related Article

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.