Compiling and running Java Programs------------------Learning notes (i)

Source: Internet
Author: User

Here is a very rough writing about the general process (if there is a mistake, please contact Bo main ^_^ in time)

  

          

Compilation of 1.java Programs

The ① compiler compiles the source file (*.java) into a bytecode file (*.class).

The Java compiler will find the corresponding Java file according to the Classpath path (not present, then error), if the class does not rely on other classes, the class is directly compiled into a. class file, if dependent on other classes,

Dependent classes are compiled, they are directly referenced, otherwise the classes that are dependent are compiled and then translated.

The compiled bytecode file mainly includes bytes: constant pool and method bytecode;

Chang: Stores all tokens (package name, class name, member variable name, etc.) and symbol references (method references, member variable references, and so on) that have occurred in the code.

Operation of 2.java Programs

②JVM Virtual machine Interpretation run bytecode file

(Note: The JVM virtual machine is only actively loading the class the first time it is used, and it is loaded only once)

Example: (Run A.java)

    

//b.java
public classB {PrivateString name; B (String name) { This. Name =name; } PublicString GetName () {returnname; } Public voidsay () {System.out.println ("My name is" +name); }}
A.java
Public classA { Public Static voidMain (string[] args) {b b =NewB ();
B.say (); }}

  

After A.JVM finds A.class, the class information of a is loaded into the method area of the runtime data area (load of Class A);

B.JVM found the main function entrance of Class A, and began to execute the main function;

C.new B () to create a B object, but this time the method area does not have Class B information, so the JVM class immediately loaded Class B, the class information of B into the method area;

D.JVM allocates space for the B instance in the heap area, and the B instance holds a reference to the class information of method area B;

E. When calling the Say () method, the JVM finds the B instance object according to the reference of B, and then locates the method table of class B information according to the reference of B instance, obtains the bytecode address of say ();

G. Implementation of the Say () method;

Reference: http://www.360doc.com/content/14/0218/23/9440338_353675002.shtml

  

    

    

Compiling and running Java Programs------------------Learning notes (i)

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.