Home > Java > Java Tutorial > body text

What are the changes to class loaders in Java 9?

WBOY
Release: 2023-08-30 15:37:02
forward
591 people have browsed it

Java 9中的类加载器有哪些变化?

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: ​​

  • The system class loader no longer exists in Java 9; it is An instance of >URLClassLoader, is an inner class. It is the default loader for classes in modules.
  • Extension ClassLoader has been renamed to Platform ClassLoader. All classes in the Java SE platform are visible through the platform class loader, and classes that are in modules under the Java community process but are not part of the Java SE platform are also visible through the platform class loader.
  • Applications cannot depend on which platform class loader is defined, some classes in the Java SE platform are defined by the platform class loader, while other classes are Bootstrap class loaderdefined.
  • If the class loader created by the existing code uses the bootstrap class loader as the parent class loader, then we need to change to use the platform class loader as the parent Class loader.
  • Platform Class Loader is not an instance of URLClassLoader, but an internal class.
  • Bootstrap class loader is a >JVM's built-in class loader. However, it defines classes for key modules, such as Base. Applications deployed using -Xbootclasspath/a or applications using null as parent to create a classloader may need to be changed.
  • ul>

    Example

    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: " + ClassLoaderTest.class.getClassLoader());
          System.out.println("Classloader of Permission: " + java.sql.SQLPermission.class.getClassLoader());
          System.out.println("Classloader of LinkedList: " + java.util.LinkedList.class.getClassLoader());
          return;
       }
    }
    Copy after login

    Output

    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
    Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!