Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is user-defined classloader?

Tags:

java

jvm

I am reading about Jvm architecture but i could't understand class loader architecture in it.I understood that what a bootstrap classloader is , but could't understand working of user-defined classloader , how it works in jvm and why it is required?

Does programmer writes user-defined classloader? I have been working on java but have not used or could't see when it's used? Please try to explain in a easy to understand way so I can exactly understand that what it is.

like image 850
Abhijeet Panwar Avatar asked Jun 03 '26 18:06

Abhijeet Panwar


1 Answers

What is user-defined classloader?

A user-defined classloader is a class (that is not provided by the standard Java libraries or 3rd-party libraries) that extends java.lang.Classloader or a subclass.

Does programmer writes user-defined classloader?

Yes.

how it works in jvm

Just like any other classloader. More specifically, to load a class, it loads the classfile into a byte[] and then calls the defineClass method implemented by the ClassLoader class. Other things may entail delegating to a parent classloader.

and why it is required?

It would be required if you need your classloader to behave differently to a normal classloader. For example, you might want to transform the bytecodes, or load them from a place that the standard implementations cannot cope with. Or you may want to implement resource loading differently to the normal pattern.

Please try to explain in a easy to understand way so I can exactly understand that what it is.

I suggest you read this IBM tutorial on classloaders: http://www.ibm.com/developerworks/java/tutorials/j-classloader/j-classloader.html It is designed to be easy to understand, and includes a worked example of a custom classloader. (It is a bit old, but that shouldn't matter.)

Alternatively, there are lots of alternatives ... as Google will tell you.

And if you just want to understand classloaders in general, read: What is a Java ClassLoader?

like image 74
Stephen C Avatar answered Jun 05 '26 07:06

Stephen C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!