Internal class
class A { //Inner1 can only be used after A is initialized, that is, it is to be called by the object A. class Inner1 { int k = 0; // static int j = 0; // After A is loaded, Inner1 is not loaded, so this static variable j cannot be used immediately, and an error is reported final int z = 0; /*static void says1() { }*/ void says2() { } } //Inner2 can use static class Inner2 { int k = 0; static int j = 0; final int z = 0; static void says1() { } void says2() { } } // Calling the inner class void c() { final int x = 0;// After final modification, new A().new Inner1();// Non-static inner class Inner1, need to call the object of the class it belongs to new A().new Inner1().say2(); A.Inner2.say1(); new A.Inner2().say2();// The non-static method says2() requires to call the object of the class it belongs to class Inner3 { void print() { System.out.println(x); } } /* * Calling of the local inner class in the method needs to be declared after the declaration, * The execution order in the method is from top to bottom, and this class * is equivalent to a local variable of course, you must first declare it, and then use */ new Inner3().print(); } } Class loader java.lang.ClassLoader
The basic responsibility of the java.lang.ClassLoader class is to find or generate the corresponding byte code based on the name of a specified class, and then define a Java class from these byte codes, that is, an instance of the java.lang.Class class. In addition, ClassLoader is also responsible for loading resources required by Java applications, such as image files and configuration files. However, this article only discusses the function of its loading class. In order to complete this responsibility of loading classes, ClassLoader provides a series of methods:
getParent() returns the parent class loader of the class loader.
loadClass(String name) loads the class with name name, and the result returned is an instance of the java.lang.Class class.
findClass(String name) looks for a class named name, and the result returned is an instance of the java.lang.Class class.
findLoadedClass(String name) looks for a loaded class named name, and the result returned is an instance of the java.lang.Class class.
defineClass(String name, byte[] b, int off, int len) converts the contents in the byte array b into a Java class, and the result returned is an instance of the java.lang.Class class. This method is declared final.
resolveClass(Class<?> c) links the specified Java class.
public class ClassLoaderTest extends ClassLoader { public static void main(String[] args) throws SecurityException, NoSuchMethodException { // root class loader, the loaded core class library URL[] urls = sun.misc.Launcher.getBootstrapClassPath().getURLs(); for (URL u : urls) { System.out.println(u); } // Extended class loader,, loaded system properties: class under the path returned by java.ext.dirs System.err.println("Extension classLoader) Loader" + ClassLoader.getSystemClassLoader().getParent());//Not inherited relationship, it is just System.out.println(System.getProperty("java.ext.dirs")); // Application (system application classLoader) class loader, loading system environment variable PATH or CLASSPATH // Specified JAR package and classpath System.err.println("Application (system) class loader" + ClassLoader.getSystemClassLoader()); // System.out.println(System.getenv("PATH")); // System.out.println(System.getenv("CLASSPATH")); } }