The first contact class is in learning jdbc. Class.forName () is a static method of the class class that is used to manually load a class, such as a database driver.
In fact, every Java class has or says a class instance object, and some tutorials explain that "everything is Object" when the class is the object of class (then class itself). The class object corresponding to each Java class is the generated class file with the same name. The primary function of class is to obtain information about a class, such as member variables/methods/constructs, and so on, and he saves the structure of the class.
When a class is used: It takes several steps to use its static method or instantiate its object: Load, connect, initialize. When the JVM loads a class, it loads its bytecode file and generates the corresponding class object. During the connection process, first verify the integrity of the class file, prepare the memory area for the static field of the class, and then parse the object. Finally initializes the class, such as executing a static statement block, initializing the static member variable.
It is important to note that there is no continuity between loading, joining, and initializing. So the difference between dynamic loading and static loading is also easier to get when it's time to load completely (static loading also checks the integrity of the class at compile time). There is a code to prove this. The JVM formally loads a class when the class is used, and the JVM dynamically loads, links, and initializes the first time the class is used.
Java.lang.Class class