One. Virtual machine working mechanism
(1): Find and Load class files by ClassLoader
(2): explanation bytecode becomes an instruction and executes, provides the runtime environment of the class file
(3): garbage collection during Operation
(4): Provides a platform for interacting with hardware
Two. Java from the code to the whole process of running
1. Create a class: Create a Java class file with a filename (the file suffix named Java) must be exactly the same as one of the class names, only the class can have the public modifier, at most one class file in a class is modified by public (inner class does not count)
The class contains the following sections: ① package definition, ② reference (Import) class, ③ class definition
2. Compile: Compile the class file into a bytecode file that can be recognized by the JVM, and the file will be named as Class suffix
3. Class Mount ClassLoader: Class loading is the JVM loading binaries into memory
4. Byte code (BYTE-CODE) Check: The JVM checks the class file for byte code, which guarantees the security of the code.
5. Explanation: The interpreter interprets the loaded bytecode file
6. Run: Run the code from runtime in the running environment
Three. Java's garbage collection mechanism
1. Purpose: deallocate allocated memory, i.e. free memory
2. Method: A system-level thread automatically tracks memory allocations and automatically recycles
3. Tip:
(1): In Java, garbage collection is an automatic system behavior, and programmers cannot control the function and behavior of garbage collection. For example, when garbage collection begins, when it ends, and what resources need to be recycled, the programmer cannot control it.
(2): There are some methods related to garbage collection, such as: System.GC (), remember, call these methods, just notify the garbage collection program, as for the garbage collection program is not running, when running, are uncontrollable.
(3): Programmers can indicate that an object is no longer needed by setting the object to null (as described later), which simply means that the object can be recycled, not immediately recycled.
Four. The security mechanism of Java
(1): The first level: The code is written first to be compiled into a class file, if the code is written in a problem, during compilation will be found, and then prompted a compilation error, can not be compiled through.
(2): The second Level: through the compilation, when the class load, the class load check, the class and network resources on this computer class separation, in the class when the check, and thus can limit any "Trojan horse" application.
(3): Third level: After the class is loaded, the bytecode check is also performed before running to determine that your program is safe.
(4): Fourth: If your program is running on the network, and the Sandbox (Sand box) is protected, what is a sandbox? That is, if your program is not authorized, it can only run within the scope of the sandbox, and it is not able to access local resources, thus guaranteeing security.
Five. Path, Classpath, java_home the respective meanings and configurations
Path: Provides paths to the operating system to find the Java command tool. is typically configured to the JDK installation path \ Bin
Java_home: Available to other Java-based programs so that they can find the location of the JDK. Typically configured to the JDK installation path. Note: This must be written correctly, all uppercase, and underlined in the middle.
CLASSPATH: The provider finds the path to the required resources at run time, such as: classes, files, pictures, and so on.
The first play of Java Foundation