Java Dynamic Proxy: The difference between JDK and Cglib, Javassist, ASM (verbose) __java

Source: Internet
Author: User
class file Introduction and Loading

After the Java compiler compiles the Java file, the. class file is generated on disk. This class file is a binary file, which is a machine code that only the JVM virtual machine can recognize. The JVM virtual machine reads the bytecode file, takes out binary data, loads it into memory, parses the information in the. class file, and generates the corresponding class object:

The class bytecode file is based on the rules of the JVM virtual machine in the code to organize the code, the specific class file is how to organize class information, you can refer to this blog: in-depth understanding of the Java class file format series. Or the Java Virtual Machine specification.

The following code shows a manual loading of the class file bytecode into the system, converting it into a class object, and then instantiating the process:

A. Define a programmer class:

[Java] view plain copy print?   Package samples; /** * Program Ape * @author Louluan * * Public class Programmer {public void code () {System.out       . println ("I ' m a programmer,just coding ..."); } B. Customize a class loader:

[Java] view plain copy print?   Package samples; /** * Custom class loader for converting bytecode to class object * @author Louluan/public class Myclassloader extends ClassLoader {PU       Blic class<?> Definemyclass (byte[] b, int off, int len) {return Super.defineclass (b, off, Len); c. Then compile into Programmer.class file, read bytecode in the program, then convert to the corresponding class object, then instantiate:

[Java]   View plain  copy  print? package samples;      import java.io.file;   import java.io.fileinputstream;   import  java.io.filenotfoundexception;   import java.io.ioexception;  

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.