1, the Narrow JavaBean specification
- The JavaBean must contain a parameterless public construction method that makes it easy to produce objects in a reflective manner.
- The property must be private.
- JavaBean must contain the get and set methods that conform to the naming convention to access the properties of the JavaBean.
- The JavaBean should be serializable (serializable).
2. Reflection
At compile time, it is unclear which class should be loaded. The load of the class is performed during run time. By reflection, classes can be loaded, examined, and self-examined.
The class template can be obtained through the object. GetClass () or through the class name. class or by Class.forName ("package name").
Field, Getdeclaredfields, and GetName can get the property name of the current class.
Methods, GetMethods, and GetName can get the method name of the current class.
Object x=n.newinstance (); Invokes the parameterless construction method of the class that produces the object of the class.
3. Java class files are loaded into memory through the ClassLoader. The ClassLoader includes the root class loader, the extension classloader, and the system ClassLoader. In addition, a ClassLoader abstract class is provided in the Java API, and developers can also create custom ClassLoader by inheriting the ClassLoader base class.
4, the root class loader is implemented with native code, it is responsible for loading the core Java class, the extension class loader is responsible for loading the extended Java class, including all javax.* beginning of the class and stored in the JRE extension directory (Java_home/jre/lib/ext) jar of the class package The system ClassLoader is responsible for loading the classes of the application itself. The root ClassLoader is also responsible for loading the extension class loader and the system ClassLoader.
5. The class loading process includes loading, connecting (validating, preparing, parsing), and initializing three stages.
6. After the class loading is complete, a corresponding class object is obtained.
7. You can make an object unavailable by assigning a reference to null, or by assigning a reference to another object, or by using a range of outliers. When an object becomes unreachable, it can be reclaimed by the garbage collector.
8. The System.GC () or RUNTIME.GC () method is the only mechanism for programmers to communicate with the JVM's garbage collector, but executing the GC () method does not guarantee that the garbage collector performs garbage collection immediately, only prompting the garbage collector to reclaim useless objects as soon as possible.
9. The finalize () method of the object can help us complete some of the finishing touches such as freeing the object lock to occupy resources. However, it is not certain that the garbage collector will execute the Finalize () method, and when the method is executed.
Java object-Oriented programming--13th chapter reflection, class loading and garbage collection