Java class loading principle and class loader

Source: Internet
Author: User


Java differs from other languages in that Java is run in Java Virtual Machines (JVMS). This means that the compiled code is
A platform-independent format that is saved instead of running on a particular machine. This format and the traditional can
There are many important differences in the execution of code formats. Specifically, unlike a C or C + + program, Java programs are not a single
The executable file is made up of a number of separate class files, each of which corresponds to a Java class. In addition, this
Some class files are not loaded into memory at once, but are loaded when the program is needed. The class loader is the Java virtual
A tool used to load classes into memory in a machine. Also, Java class Loaders are implemented in Java. So you don't need
A deep understanding of Java virtual Machines makes it easy to create your own classloader.
Why would I want to create a class loader?
Now that the Java virtual Gold has a class loader, what else do we have to create ourselves? Good question. The default class loader
Only know how to load classes from the local system. When your program is fully compiled on the local computer, the default ClassLoader is generally
Very well done. But one of the most exciting parts of Java is that it's easy to load classes from the Web rather than just the locals.
For example, a browser can load a class from a custom class loader. And also
Many ways to load classes. In addition to the simple local or network, you can also customize Java by customizing the most exciting
One of the places:
* Automatically validate digital signatures before performing untrusted code
* Decrypt code based on user-supplied password
* Dynamically create class based on user's needs
Everything you care about can be easily integrated into your application in bytecode form.
Examples of custom class loaders
If you have already used the Appletviewer (small application browser) in the JDK (Java Software development package) or other
Java Embedded Browser, you have already used the custom class loader. When Sun just released the Java language, the most
One exciting thing to watch is how Java executes code that downloads from a remote Web site. Execute from remote site via HTT
The byte code sent by the P connection looks a little weird. It works because Java has the ability to install custom classes Plus
The ability to carry the device. The small application browser contains a class loader that does not look for Java classes locally, and
is to access the remote server, load the original bytecode file with HTTP, and then convert it into a Java class in the Java virtual machine. When
The ClassLoader also does many other things: they block unsafe Java classes and keep different pages
Small programs don't interfere with each other. Luke Gorrie writes a package echidna is an open Java software package that he allows in
Run multiple Java applications securely in a Java virtual machine. It is given to each application by using the custom class loader
Order a copy of the class file to block interference between applications.

Java class loader :

There are three kinds of loaders by default in Java: Boot class loader, extended class loader, System class loader (also called Application class loader)

The ClassLoader is one of the most powerful features of Java. But developers often forget class loading components. Class loaders are classes that are responsible for finding and loading class files at run time. Java allows you to use a different class loader, or even a custom classloader.

Java programs contain many classes of files, each corresponding to a single Java class, which is not like a static C program, loaded into memory at any time, and they need to load at any time. This is where the ClassLoader is different. It obtains the platform-independent bytecode from source files (usually. class or. jar files) and loads them into the JVM memory space, so they can be interpreted and executed. By default, each class of the application is loaded by Java.lang.ClassLoader. Because it can be inherited, it is free to enhance its function.

< </

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.