The above code pro creates a static Properties object
JDBCUtil.class is the Class object that creates a JDBCUtil
There may be many people who do not know what a Class object is. Here is a brief introduction
Class class: When a Java program is running, the Java runtime system always performs the so-called runtime type identification on all objects, the so-called RTTI. This information records the class to which each object belongs. The virtual machine usually uses the runtime type information to select the correct method to execute. The class used to store this type information is the Class class. The Class class encapsulates the runtime state of an object and an interface. When a class is loaded, an object of the Class type is automatically created.
Each class has a Class object.
The Class class is also a type of class, but the name and the class keyword are highly similar. Java is a case-sensitive language
. The object content of the Class class is the type information of the class you created. For example, if you create a shapes class, then Java will generate an object of the Class class whose content is shapes. The object of the
Class class cannot be like a normal class. In the same way, created in the way of new shapes(), its object can only be created by the JVM, because this class has no public constructor
. The role of the Class class is to provide or obtain the type information of an object at runtime, and the typeid( ) function similar to
Class is the basis of reflection technology. If you want to manipulate the properties and methods in the class, you must start
with the way to obtain the Class object: the Class object is created by the virtual machine and can only be obtained
JDBCUtil.class.getClassLoader() is the class loader to get the JDBCUtil class
There is such a method in the Class class in the API documentation, which returns a class loader
JDBCUtil.class.getClassLoader().getResourceAsStream("jdbc.properties") is to return an input stream that reads the specified resource
Refer to API documentation
returns an input stream
pro.load(in) is to read the list of properties from the input stream
Refer to API documentation