What are cool loaders in Java?

When a client says “code should not have custom classloaders” in Java, what does this mean? What can not I do?

+6
java classloader
source share
4 answers

A class loader is an object in Java responsible for finding binary representations of Java classes and loading them into the JVM. All JVMs start with the boot class loader responsible for loading the user's initial class, as well as some built-in types such as Class and SecurityManager , but users can provide their own class loaders to search for classes from other sources. For example, a custom classloader can generate its own classes by creating its own bytecode, or it can find classes from a network source.

To match your client’s needs, you don’t have to define your own classloader and you must rely on the bootloader to find all your classes. This is almost universally the case with simple Java programs, because use cases for custom loaders are usually quite complex and nuanced. You do not need to worry about this limitation unless you specifically want to change the way that these JVM classes are discovered and loaded.

+12
source share

Custom class loaders are typically used to dynamically generate code or to enhance existing classes.

For example, some ORM (JDO) implementations use this to create code that handles the translation of Java objects into database tables. Another use is in solutions with transparent clustering (for example, Terracota), where objects are expanded so that they automatically copy themselves through the cluster.

This basically does not allow you to dynamically generate and enter code into an existing application.

+1
source share

A class loader is an object that is responsible for loading classes. Whenever you instantiate a class using new , the runtime system attempts to load the class using one or more instances of the abstract class ClassLoader. You can define custom class loaders to load classes from the network, databases, other processes, or any possible data source.

So, if your client does not want you to use custom class loaders, remember to never write a class that extends ClassLoader or any of its derivatives. See the ClassLoader java API docs for more details.

0
source share

A custom class loader allows you to load classes from non-traditional sources (from any place you can imagine, including from nowhere, that is, created on the fly). Since your client is talking about this message, classes can only be loaded from standard sources (e.g. file system, jar files, etc.).

0
source share

All Articles