"Java Depth Adventure" reading notes (i)

Source: Internet
Author: User
Tags command line implement modify parent directory variable
Notes
Recently began to see

Mr. Sen Wang's "Java Depth Adventures", from the one I borrowed this book to Fondle admiringly, the contents of the book is very attractive. It can be said that this book helps us to have a deeper understanding of the Java program running process. So I will record some important conclusions in the book for your reference, as well as your own notes.









The first chapter:

There are at least two JRE in our machine, set in%java_home%/jre, set in%home%/program files/java/jre1.x.x, then when we enter JAVA at the command line XXX will follow the logic below to find the appropriate JRE to execute the program:

1. Current directory

2. JRE subdirectory under the parent directory

3. Query the JRE inside the registry

So we must be careful when configuring environment variables.









Chapter II:

When you construct a class, you can dynamically load memory, which increases efficiency to some extent, and all classes need to be classloader.

There are two ways to explicitly dynamically load classes: one is Class.forName (), one is Classloader.loadclass (), they get the class object, the metadata for the corresponding class, and then call Newinstance () method to construct an object of this class. Both methods have the principle of having a classloader to load the class. We can load the class directly using the default ClassLoader, or we can implement our own ClassLoader (URLClassLoader is an example) to load.

The focus of the book is the principle of the default ClassLoader loading class. The JVM has three ClassLoader, Bootstrap Loader (this one is written in C + +, dealing directly with the JVM), Extclassloader,appclassloader. By default, Appclassloader is first requested to search for a class file, Appclassloader to its parent class Extclassclassloader request, Extclassclassloader to request its parent "class "Bootstrap Loader search. If the parent loader does not find a class file in its search path and then searches by the loader, it throws noclassdeffounderror if it is not found until Appclassloader. This is ClassLoader hierarchy, in short, that all reprint requests are sent to the bootstrap Loader and cannot be found before being loaded by a child loader.

The following is a search path for 3 reprints:

Bootstrap Loader:System.getProperty ("Sun.boot.class.path"); get, default is jre/classes. The modified method is to execute the program when using Java-dsun.boot.class.path=yourpath XXX

ExtClassLoader:System.getProperty ("Java.ext.dirs"): Get, Default is Jre/lib/ext. The modified method is to execute the program when using Java-djava.ext.dirs=yourpath XXX

AppClassLoader:System.getProperty ("Java.class.path"); The default is the CLASSPATH in the environment variable. Modifying a method is to modify the environment variable, a program to execute the time using Java–classpath Yourpath XXX

With this understanding, we can have a certain understanding of the loading of the class, the next place when the third party jar package can be clearly put in what directory is most appropriate. Of course, the book also said that JDBC driver and Jndi class loading involves contexclassloader, which is not the same principle, and is not described in the book.

Chapter III:

The JNI technology is introduced through an example of creating a Word document.

Because Java programs are executed on a JVM basis, there are many features that are closely related to the underlying operating system that are difficult to implement. We can modify a local method with the native keyword, and this method is implemented by other languages. This allows us to invoke the Windows DLL and the Unix/linux so file to interact with the underlying operating system.

To be Continued ...


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.