A. class file can contain only one class or interface. So how many classes are defined in the. java file, and how many. class files (internal classes do not count) are generated at compile time.
The 2.java program can choose two ways to access the underlying system, which is chosen by the programmer: (1). Call Javaapi via Java program to call the local method, access the underlying system, regardless of the platform. (2). Call the local method directly through the Java program to access the underlying system related to the platform. The local method is the method provided by the operating system.
3. Class Loaders: Loading the Java compiler compiled bytecode *.class and Java API bytecode to the method area.
Java has two kinds of loaders: (1). Start class Loader: System only, part of the virtual machine, written in a specific language (with the virtual Body Layer language) Use the default way to load classes, mainly used to load the core class library
。 (2). user-defined class loader: can have any number of, written in Java, part of the Java application, can be compiled into bytecode, and is loaded by the virtual machine.
A loader loads a class and all classes called by that class, makes them interconnected and forms a namespace (name space), and each class loader corresponds to a namespace.
The principle of namespaces in Java.
Class loaders are aligned in a linear, bottom-up, top-starting class loader. In addition to starting class loaders, other class loaders are instantiated by the user to load different classes. When you want to load a
class, the bottom loader attempts to give the class to the parent loader and the parent class attempts to load the parent class up until the class loader is started. If the parent class loader cannot
Load, then to the subclass loader load, the subclass loads the part that can be loaded, and the remainder to his subclass until the bottom is over. such as: Loader a,b,c,d,e,f, start a--->b--->c--->d--->e--->f the---> Startup when a class fun needs to be loaded, he will go up to the top and start the class loader. If the boot class loader cannot load the fun, it is given to the F load, the F load can load the part, will it
The remainder is given to E, and then it goes on.
As mentioned above, the classes loaded by each class loader during the run form a Run-time package, and classes in the same Run-time package can access each other, but cannot access classes outside the package.
4. Virtual machine life cycle: Each Java program has its own virtual machine instance, with the production and extinction of the program and extinction.
5.java Program Runtime memory structure: program space is divided into method area, heap, Java stack, local method stack.
(1) The method area holds the loaded class data information including: basic information: The fully qualified name of each class. The fully qualified name of the direct superclass of each class (a constraint type conversion). Whether the class is a class or an interface. The access modifier for this type. An ordered list of fully qualified names for the direct hyper-interface.
Details of each loaded class: Run a constant pool: All constants used to hold the type (direct constants and symbolic references to other types, fields, methods), which are accessed as an array through the index, are external calls
A bridge that relates to classes and types of objects. It is the run-time representation of a class file (bytecode) constant pool. (There is also a static constant pool, in a bytecode file). Field information: Information (name, type, modifier) for each field declared in the class. Method information: Information about each method declared in the class (name, put back type, parameter type, modifier, byte code of method, and exception table). Static variable to class ClassLoader reference: That is, a reference to the class loader of the class. Reference to Class class: The virtual machine creates a class instance for each loaded type to represent the loaded class.
(2) The heap holds all the generated objects and the instance variables of the objects.
(3) The Java stack holds the invocation state of the local method (including the parameters of the method call, local variables, intermediate results, etc.) in the shape of the frame. Each method is invoked to push the method frame into the
Java stack, which becomes the current method frame. When the call ends (returns), the frame pops up. When the compiler compiles the original code into bytecode (. Class), it has already changed the local size of the various types of methods
Quantity, the operand stack size is determined and placed in the byte code, and the class is loaded into the method area together. When the method is invoked, the local variable and the operand are obtained by accessing the information of the class in the method area
The size of the stack.
Java stack frame (i.e. method frame) is composed of local variable area, operand stack and frame data area.
The local variable is an array of words, with each array element corresponding to the value of a local variable. When a method is invoked, the local variable of the method is formed into an array, and the index is used to access the
。 For non-static methods, add an implied reference parameter this, which points to the object that called the method. Static methods, however, do not have the This parameter. Therefore, the object cannot invoke the static
The operand stack is also an array, but it is accessed through stack operations. The so-called operands are those data which are instructed to manipulate. When a parameter operation is required, such as A=B+C, the parameters that are about to be manipulated are
The number of pressure stacks, such as the B and C stack, and then by the operation instructions will they eject, and perform operations, here by the iadd instruction will b and C pop-up and add, and then into the operand stack (a series of Iadd
Row) and then the i_storex instruction pops the result and saves it to the array of local variables to which the index x points (where the index x points to local variable a). The virtual machine takes the operand stack as the workspace.
The frame data area handles constant pool parsing, exception handling, and so on.
(4) Local method stack: associated with the language of the local method being invoked, such as a C-language method called a C stack. Local methods can recall Java methods. If a Java method invokes a local method, the virtual machine runs the local method. In the case of a virtual machine, running this local method is to execute this Java method, if the local method throws an exception,
The virtual machine thinks that this Java method throws an exception.
(5) When executing a program, look up the loaded class in the method area by reference to the object, and if it is not yet mounted, look for the byte code (class name. Class) and load it into the method area. During execution, the virtual opportunity replaces the object's symbolic reference (that is, the object name) with a direct pointer to increase the speed of the access.
(6) Therefore, the general can be expressed as: Method area: The storage class includes the various information of the interface, the bytecode is loaded here. Java stack: Stores the various information about the invoked method, which is pressed into the Java stack only when the method is invoked. Heap: Stores information about an object, including an object's instance variable, but does not include methods for the object. The method frame is pressed into the Java stack only if the object's method is invoked.
6.java data type: Numeric type: Floating-point type: float double integer type: byte,short,int,long,char (int and char can be interchanged). Reference type: Class type, interface type, array type.
Reference type for 7.java: reference and pointer. A reference represents the referenced object, it is simply a representation of the object, does not occupy memory, and cannot be modified. If the reference variable does not refer to the object, the reference variable =null. The pointer holds the address of the object, which is a variable that can be modified and, like other variables, consumes memory.
8. The method area is shared by all threads, but for thread safety, each class in the method area must be set as a critical resource, that is, a class can only be accessed by one thread at the same time.
9. Class Identity: Because a program can load the same class multiple times and the class can exist in different namespaces (which can be loaded by different loaders), the identity of the loader that loads the class must be added
To uniquely identify a class.
10. Object object instance variables are stored in the heap, and object symbol references are in a constant pool, where the method property sheet may appear. An object's reference allows access to the object's instance data and the creation of the object
The data for the class. Object refers to objects in the heap. The instance structure has two kinds, see Book 98 pages.
Dynamic binding is required when the object's methods are invoked. That is, you cannot determine the method that needs to be invoked based on the object, but instead determine the method that needs to be invoked based on the object's class data. Now
You also need to access the class data through a reference to the object. Dynamic binding is binding at run time, not at compile time.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to email@example.com. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.