Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between loadClass(String name) and loadClass(String name, boolean resolve)

What is the difference between loadClass(String name) and loadClass(String name, boolean resolve) ?

The only difference I know is loadClass(String name, boolean resolve) calls findLoadedClass(String) if the resolve parameter is true?

So when is true or false passed to resolve parameter ?
I'm confused a lot between this two functions.

Thanks.

like image 384
Searock Avatar asked Mar 25 '11 05:03

Searock


People also ask

What is ClassLoader in Java and what are types of 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. Java classes aren't loaded into memory all at once, but when required by an application.

What is Java lang ClassLoader?

A class loader is an object that is responsible for loading classes. The class ClassLoader is an abstract class. Given the binary name of a class, a class loader should attempt to locate or generate data that constitutes a definition for the class.

How many types of class loader are there?

There are three types of built-in ClassLoader in Java. Bootstrap Class Loader – It loads JDK internal classes. It loads rt. jar and other core classes for example java.

What are the different class loaders in Java?

As we can see, there are three different class loaders here: application, extension, and bootstrap (displayed as null). The application class loader loads the class where the example method is contained.


1 Answers

The resolve parameter controls whether the class that's loaded is linked or not. During linking, static constants are initialized and have their memory allocated. Additionally, the class is verified for correctness, and possibly links to other classes will be resolved.

This could be useful, for example, if you wanted to load in a new class that may be malformed and don't want the JVM to throw verification errors in the event that the class is buggy.

like image 188
templatetypedef Avatar answered Sep 28 '22 18:09

templatetypedef