Ans: Phases of class loading
The are three phases of concrete class loading: physical loading, linking, and initializing.
1) In in first phase of physical loading required class file will be searched in specified classpaths. If the file is found it is read and the bytecode is loaded. This process gives a basic memory structure to the class object, such concepts like methods, fields, and other referenced classes are not known at this stage.
2) Linking can be broken down into three main stages, because it is complex phase:
1.Bytecode verification through class loader, which executes a number of checks on the bytecodes.
2.Class preparation. This stage prepares the necessary data structures that represent fields, methods and implemented interfaces that are defined within the class.
3.Resolving of all the other classes referenced by a particular class. The classes can be referenced in a number of ways:
- Field types
- Types in method signatures
- Types of local variables used in methods
3) During the initializing phase any static initializers contained within a class are executed so that, static fields are initialized to their default values.
It is interesting, that class loading can be performed in a lazy manner and therefore some parts of the class loading process may be done on first use of the class rather than at load time.