Java source code compilation Mechanism

Source: Internet
Author: User

The JVM Specification defines the format of the class file but does not.Source codeHow to compile it as a class file, so major vendors compile it as a class file in compliance with the specifications when implementing JDK. The following uses Sun JDK for analysis.

The basic process is as follows:

{Java source file} ------- >{analyze and inject to the symbol table (parse and enter)} ------ >{annotation processing )} ---------> {Semantic Analysis and generation of class files (analyse and generate)} --> {0101}

The following describes the processes:

1. Analyze and inject to the symbol table

The analysis process mainly involves lexical and syntax analysis.

The injection process mainly involves inputting the symbol table into the symbol table ., Generally, this includes super classes and interfaces of the class. You can add the default constructor as needed to input the symbols in the class to your own symbol table.

2. Watching

It mainly processes users' own annotation, which may bring about the benefit of generating additional annotations Based on annotation.CodeOr perform some special processing to save some code writing, such as writing the get and set methods. The compilation will be automatically generated after compilation through annotations.

3. Semantic Analysis and generation of class files

It is mainly used to associate elements such as names and expressions with variables, methods, types, and so on. It checks whether the variables have been declared before use, and whether they are generic and type-matched, check that all statements can be reached, and the checked exceptions must be caught or thrown. check whether there is a return value to determine whether there is a return value. Check that the variables do not assign values repeatedly and retrieve useless Code such: if (false ){//....}, there are also generic conversion to common Java types, as well as automatic unpacking and packing conversion. Finally, the class file is generated.

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.