All About Class ClassLoader in Java

The ClassLoader is an abstract class. The applications implements sub classes of Classloader in order to extends mechanism by which JVM dynamically loads classes.In general JVM loads classes from local file system in a platform dependent manner(directory defined by CLASSPATH),however some classes may be originated from other source  like network or by an application.The method defineClass() converts an array of bytes into an instance of a class.Instances of this newly created /defined class can be created by using the newInstance() method of the class-Class.The methods and constructors of objects created by a ClassLoader may reference other classes.To determine the class(es) referred to, the JVM calls the loadClass() method of the ClassLoader that originally created the class. If JVM only needs to determine if the class exists or if it does not exists,to know its super class,the resolve flaf is set to false.However if an instance of the class is being created or any of it's method is being called,the class must also be resolved.In this case the flag resolve is set to true and resolveClass() method is called.
The structure of  ClassLoader class is given below:

public abstract class java.lang.ClassLoader extends java.lang.Object{
protected ClassLoader()
//creates a new classloader and initializes it. if there is a security manager, it check by createClassLoader() method.It may result in a SecuryException if the current thread does not have permission to create a new ClassLoader.
protected final class defineClass(byteData[],int offset,int length);
protected final class findSystemClass(String name);
protected final void resolveClass(Class c);
protected abstract Class loadClass(String name,boolean resolve);
All About Class ClassLoader in Java All About Class ClassLoader in Java Reviewed by Animesh Chatterjee on September 21, 2018 Rating: 5

No comments:

Powered by Blogger.