About Java class loader types

Summarize Java class loader.

boostrap class loader

Example.java


public class Example
{
    public static void main(String[] args)
    {
        System.out.println(String.class.getClassLoader());
    }
}
$ javac Example.java && java Example
null

extension class loader

Example.java


import sun.net.spi.nameservice.dns.DNSNameService;

public class Example
{
    public static void main(String[] args)
    {
        ClassLoader extLoader = DNSNameService.class.getClassLoader();
        System.out.println(extLoader);
        System.out.println(extLoader.getParent());
    }
}
$ javac Example.java && java Example
[email protected]
null

user class loader

example/A.java


package example;

public class A
{
}

Example.java


import example.A;

public class Example
{
    public static void main(String[] args)
    {
        ClassLoader appLoader = Example.class.getClassLoader();
        System.out.println(appLoader);
        System.out.println(appLoader.getParent());
        System.out.println(appLoader.getParent().getParent());
        System.out.println();

        appLoader = A.class.getClassLoader();
        System.out.println(appLoader);
        System.out.println(appLoader.getParent());
        System.out.println(appLoader.getParent().getParent());
    }
}
$ javac example/A.java && jar cf example/A.jar example/A.class
$ javac Example.java && java -classpath example/A.jar:./ Example
[email protected]
[email protected]
null

[email protected]
[email protected]
null

Reference URL

Recommended Posts

About Java class loader types
About Java class
About class division (Java)
About Java StringBuilder class
[Java] About Singleton Class
About Java String class
About java abstract class
About Java class variables class methods
About Java primitive types and reference types
About Java interface
Java class methods
[Java] About Java 12 features
[Java] Class inheritance
Java HashMap class
About class inheritance.
java (abstract class)
Something about java
Where about java
About Java features
[Java] Nested class
Java anonymous class
About Java threads
[Java] About interface
About Java arrays
About java inheritance
About interface, java interface
[java] abstract class
[Java] Object class
Java local class
About List [Java]
About java var
About Java literals
About Java commands
About Java data types (especially primitive types) and literals
Java, about 2D arrays
About the StringBuilder class
About [Java] [StreamAPI] allMatch ()
About Java method binding
[Java] About anonymous classes
About method splitting (Java)
Java inner class review
[Java Silver] About initialization
About Java Array List
About Java Polymorphism super ()
[Swing] About JFrame class
Java class type field
About inheritance (Java Silver)
Java programming (class method)
About Java access modifiers
[Swift] About enumeration types
About Java lambda expressions
About Java entry points
About Java 10 Docker support
Personal summary about Java
[Java] Main data types
About sorting java.util.Arrays class
[Java] About enum type
Java programming (class structure)
All about Java programming
[Java] Variables and types
Java basic data types