Question20180104 comparison compiler, interpreter and Javac compiler principle

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). In the last run, the Machine code (NATIVECODE) can be programmed to be computed directly by the CPU by 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, does not need the compiler at execution time, runs directly on the platform which supports the target code, so the execution efficiency 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, which describe in detail what grammar and vocabulary The language has,Javaas a high-level development language is no exception, it also has its own language specification,Javavirtual machines also have their own virtual machine specifications,Javathe virtual machine specification andJavaLanguage Specification is not the same thing, they all have their own lexical and grammatical parsing rules, and their analytic rules are different. So how can we makeJavathe grammatical rules fitJavaWhat are the syntax rules for virtual machines? This task is done byJavaccompiler to complete. Its role is toJavathe language specification translates intoJavaVirtual Machine Language Specification, complete"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 developed by C, Java is a compiled language, but also an interpreted language, and C is a compiled language, C, the source code after a compilation can be directly to the computer to execute, and Java sources need to compile a compilation to meet the JVM specification of the intermediate code, The JVM then interprets the execution of the machine code that can be recognized by the computer and is executed by the CPU at last. such as:

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.

Question20180104 comparison 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.