Java Reflect (Java beginner)

Source: Internet
Author: User

To talk about reflection, we have to figure out class object, because reflection provides methods that are provided by class object.

The following is the class comment for Java.lang.Class:

  


The Primitive Java types (Boolean, Byte, char, short, int, long, float, and double), and the keyword void is also Represe nted as Class objects. Class has no public constructor. Instead Class objects is constructed automatically by the Java Virtual machine as classes is loaded and by calls to the,
DefineClass method in the class loader

Http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8-b132/java/lang/Class.java

Java.lang.Class represents all the types that are loaded at run time, including instances of classes or interfaces. The class object is generated by the JVM (see Javascipt for the principle of object-oriented programming, how to control the creation of type one meaning). Let's take a general description of the JVM's process of finer (creating) a class:

Assuming we run the Java path/to/sth.class file (with the main function),

1. JVM initialization:

The Java program goes back to find the JVM implementation (for example, the Windows system is Jvm.dll) and initializes the JVM.

2. Initialization of Class Load:

After the JVM finishes initializing, run Bootstraploader (c), which will create 2 Java versions of Class Loader:extclassloader (Sys level ext Path) and Appclassloader (APP level Path) (the process, we will continue to be in the JVM after the road).

Then set the parent of Extclassloader to self (BootStrap Loader), set Appclassloader's parent as Extclassloader, complete ClassLoader

The inheritance relationship. The function of this inheritance is that the load Class method implemented by the JVM is carried out according to the inheritance relationship, which is first assigned to the parent load, and if no Class is found, it will

To find. This also avoids the condition of repeated loading. (Of course we have a way to get a class to be loaded 2 times in the same JVM, but it's not useful yet)

3. Use the class loader mechanism to load sth.class. Because Bootstrap Load,extclassloader all find not this class, finally handed a appclassloader to find, Carry on Load.

Run.

Here's a look at each class loader looking for a path:

BootStrap Loader's classpath path is system.getproperty ("Sun.boot.class.path")

The Extclassloader class path path is System.getproperty ("Java.ext.dirs").

The classpath of Appclassloader is system.getproperty ("Java.class.path").

We often use CLASSPATH to configure the environment variable designation, so remember to add one. In Classpath, OH. Of course, you can also cover this path by-CP.

So, if you have Java running a class that appears classnotfoundexception, use the above logical strands.

Java Reflect (Java beginner)

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.