16 Şubat 2023 Perşembe

Java 8 ClassLoader Sınıf Yükleme Sırası

Giriş
Açıklaması şöyle. Yani 3 tane sınıf var. Bunlar şöyle 
1. BootStrap ClassLoader 
Açıklaması şöyle
JVM İlk Yüklenirken Çalışır
2. Extension ClassLoader
Açıklaması şöyle
The extension class loader is a child of the bootstrap class loader, and takes care of loading the extensions of the standard core Java classes so that they're available to all applications running on the platform.

The extension class loader loads from the JDK extensions directory, usually the $JAVA_HOME/lib/ext directory, or any other directory mentioned in the java.ext.dirs system property.
3.Application ClassLoader veya System ClassLoader
Açıklaması şöyle
Kendi sınıflarımızı yükler
Açıklaması şöyle
The system or application class loader, on the other hand, takes care of loading all the application level classes into the JVM. It loads files found in the classpath environment variable, -classpath, or -cp command line option. It's also a child of the extensions class loader.

Şeklen şöyle

Örnek
Elimizde şöyle bir kod olsun
import com.sun.javafx.util.Logging;
import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.util.ArrayList; public class PrintClassLoader { public void printClassLoaders() throws ClassNotFoundException { System.out.println("Classloader of this class:" + PrintClassLoader.class.getClassLoader()); // Kendi kodumuz System.out.println("Classloader of Logging:" + Logging.class.getClassLoader()); // Extension kodu System.out.println("Classloader of ArrayList:" + ArrayList.class.getClassLoader()); // JDK kodu } }
Çıktısı şöyle.
Class loader of this class:sun.misc.Launcher$AppClassLoader@18b4aac2
Class loader of Logging:sun.misc.Launcher$ExtClassLoader@3caeaf62
Class loader of ArrayList:null




Hiç yorum yok:

Yorum Gönder