All java programs run on Java Virtual Machine (JVM). After compilation, java classes are converted to platform and machine-independent bytecode , and the compiled classes are stored as .class files. Whenever we try to use it, ClassLoader will load the class into memory. These classes are introduced into the Java environment when they are referenced by name. Once a class starts running, the loading of the class is done by the class loader, and the main() method is one way to start the class.
There are some minor changes to class loaders in Java 9:
public class ClassLoaderTest { public static void main(String args[]) { System.out.println("Class Loader Test"); ClassLoaderTest test = new ClassLoaderTest(); try { test.showClassLoaders(); } catch(ClassNotFoundException cnfe) { System.out.println(cnfe.getMessage()); } } public void showClassLoaders() throws ClassNotFoundException { System.out.println("Classloader of this class: " + <strong>ClassLoaderTest.class.</strong><strong>getClassLoader()</strong>); System.out.println("Classloader of Permission: " + <strong>java.sql.SQLPermission.class.</strong><strong>getClassLoader()</strong>); System.out.println("Classloader of LinkedList: " + <strong>java.util.LinkedList.class.</strong><strong>getClassLoader()</strong>); return; } }
<strong>Class Loader Test Classloader of this class: jdk.internal.loader.ClassLoaders$AppClassLoader@504bae78 Classloader of Permission: jdk.internal.loader.ClassLoaders$PlatformClassLoader@299a06ac Classloader of LinkedList: null</strong>
The above is the detailed content of What are the changes to class loaders in Java 9?. For more information, please follow other related articles on the PHP Chinese website!