Knowledge point 20180303 vs. compiler, interpreter, and Javac compilation principles

Source: Internet
Author: User

Compiler and javac compilation principle

in the previous article, we know.   Java is a compiled and interpreted language whose source code is compiled by the compiler javac into a binary language that can be recognized by the JVM, and the JVM interprets it as a machine language that can be recognized by the platform. So what is a compiler? What is the role of the compiler? How does Javac work? Below we hit know understand.

1 Compiler (Compiler)

Simply put, a compiler is a program that translates "one language (usually a high-level language)" into "another language (usually a low-level language)". A modern compiler's main workflow: source code → preprocessor (preprocessor) → compiler (compiler) → object code → linker (Linker) → executable Program (EXECU Tables

Advanced computer languages are easy to write, read, communicate, and maintain. Machine language is the computer can be directly read and run. The compiler translates the assembly or Advanced computer language source program as input into the equivalent program of the target language (destination language) machine code. The source code is generally a high-level language (high-level language), such as Pascal, C, C + +, Java, Chinese programming, or assembly language, and the target is the machine language object code (object codes), sometimes called machine code.

For high-level languages such as C #, VB, the compiler completes the function of compiling the source code (SOURCECODE) into a common intermediate language (Msil/cil) bytecode (bytecode). The final runtime is converted to a machine code (NATIVECODE) that can eventually be computed directly by the CPU through the conversion of the common language runtime.

Simply put, the compiler is the "one language (usually a high-level language)" translated into "another language (usually low-level language)" program, the role of the compiler is to facilitate human understanding of the language norms into the machine easy to understand the language specification;

2 Interpreter

Interpreter (  English: Interpreter), also translated as a computer program, can be a high-level programming language line direct translation run. The interpreter does not translate the entire program at once, just like an "intermediary", and each time the program is run, it is turned into another language to run, so the interpreter's program runs slower. It runs at once with every translation of a single line of programming, then translates the next line, then runs, so it goes on.

3 Comparison of interpreter and compiler

The interpreter is a one-piece explanation of the execution source language. For example, Php,postscritp,javascript is a typical interpretive language.

The compiler compiles the source code all the way to the target code, executes it no longer requires the compiler, and runs directly on the platform that supports the target code, which is much faster than the interpretation execution. For example, C language code is compiled into binary code (EXE program), executed on the Windows platform.

The interpreter is much more efficient than the compiler (see http://www.cnblogs.com/sword03/archive/2010/06/27/1766147.html)

4 Javac Compilation principle

We know that the programming language has its own specifications, this specification describes in detail what language has syntax and vocabulary, Java as a high-level development language is no exception, it also has its own language specification, Java Virtual Machine also has its own virtual machine specification, Java Virtual Machine specification and Java language Specification is not one thing, They all have their own lexical and grammatical parsing rules, and their parsing rules are different. So how can the syntax rules of Java be adapted to the syntax rules of Java virtual machines? This task is done by the Javac compiler. Its role is to translate the Java language specification into the Java Virtual Machine Language specification to complete the "translation" work.

What is 4.1 javac?

Javac is a compiler that translates a language specification into another language specification. Usually compilers are easy-to-understand language specification into the machine easy to understand the language specification, such as C, C + + or assembler is the source code directly compiled into the target machine code, the target machine code is directly executed by the CPU instruction set. These instruction sets are the underlying language specification, and the machine is able to directly identify the language specification, but people cannot directly write the target machine code. Although this machine code execution is very efficient, but very unfriendly to people, the cost of developing this code is often higher than the cost of the implementation of the saved machine, so the compiler appears, with the compiler is likely to appear so many high-level programming language.

In a sense, the compiler has the programming language boom, because the compiler is a link between human and machine communication.

5 java you are slower than C

We know that Java is the development of C + +, Java is a compiled language, but also an interpreted language, and C + + is a compiled language, the source code after a compilation can be directly on the computer (compiled C code for the computer platform-specific machine instructions, To another platform needs to be recompiled) execution, while Java source code needs to be compiled once to generate the JVM specification of the intermediate code, and then by the JVM interpretation of the execution of generating machine code can be recognized by the computer, and finally by the CPU execution. For example:

So it's obvious that Java is running without C so direct, so quickly, for this disadvantage, the JVM has an option to translate a high-frequency byte-code sequence into machine code, a process called instant compilation, which greatly provides execution efficiency.

Knowledge point 20180303 vs. compiler, interpreter, and Javac compilation principles

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.