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)