Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java class loader tutorial [closed]

Please provide a good, thorough tutorial about Java class loading, focusing on how to extend that mechanism and how to actually work with the extension.

like image 312
Yaneeve Avatar asked Nov 04 '09 11:11

Yaneeve


People also ask

Why ClassLoader is used in Java?

Class loaders are responsible for loading Java classes dynamically to the JVM (Java Virtual Machine) during runtime. They're also part of the JRE (Java Runtime Environment). Therefore, the JVM doesn't need to know about the underlying files or file systems in order to run Java programs thanks to class loaders.

Where is ClassLoader in Java?

The Java ClassLoader is a part of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine. The Java run time system does not need to know about files and file systems because of classloaders.

Can JVM can exist without a class loader?

Each application might use different versions of the same libraries, and must thus have a different classloader from the others in order to be able to have different versions of the same classes in a single JVM. but the web server has its own loader.it can have several classloaders.

Can we create our own ClassLoader in Java?

We will create our own ClassLoader by extending the ClassLoader class and overriding the loadClass(String name) method. If the class name will start from com. journaldev then we will load it using our custom class loader or else we will invoke the parent ClassLoader loadClass() method to load the class.


2 Answers

There's obviously Sun's trail which gives you the technical foundations. I find that despite being thirteen years old(!) this JavaWorld article is still a very good place to start - the technicalities of classloading haven't changed much or at all since then, to my knowledge. (Someone please correct this if there have been any important changes since then!).

IBM are usually good for technical Java articles, and they don't disappoint here. O'Reilly also have a more recent article that covers much the same thing but has a pretty diagram in it. :-)

like image 64
Andrzej Doyle Avatar answered Sep 20 '22 18:09

Andrzej Doyle


The Mindprod Java Glossary has a good description of what a classloader is and lists tutorials and technical articals at the end of the page.

like image 40
rsp Avatar answered Sep 19 '22 18:09

rsp