Knowledge points during the school project: Java, java2015
# Run the Java program through the command line
1. File
The source code of Java is stored in a file with the extension ". java;
After the Java source file is compiled, the ". class" file is obtained.
2. Method
How to compile java source code in the command line: javac file name. java
Execute the. class file in the command line: java file name (if the file has the main method, execute it directly)
# Class Lifecycle
After a class is compiled, you need to use the class in the next step. To use a class, you must not use JVM. During program execution, the JVM completes the three steps of loading, linking, and initializing.
The class is loaded by the class loader. the binary file of the class file is loaded into the JVM method area, and the java. lang. class Object. Used to encapsulate data. However, the same class will only be loaded once by the class loader.
The link is to assemble binary data into a running state.
Links are divided into three phases: verification, preparation, and resolution.
Verification is generally used to verify whether the binary file is suitable for the current JVM (version ),
Preparation is to allocate memory space for static members ,. And set the default value
Parsing refers to the process of converting the code in the constant pool as a direct reference until all symbolic references can be used by running programs (establishing a complete ing relationship)
After initialization, the type is complete, and the class object can be used normally after initialization, until an object is no longer used, it will be recycled. Release space.
When no reference points to a Class object, it will be uninstalled to end the lifecycle of the Class.
# Methods for creating objects in Java
Http://blog.csdn.net/mhmyqn/article/details/7943411
There are four explicit object creation methods:
1. Use the new statement to create an object. This is the most common method to create an object.
2. Use reflection to call the newInstance () instance method of the java. lang. Class or java. lang. reflect. Constructor Class.
3. Call the clone () method of the object.
4. Use deserialization to call the readObject () method of the java. io. ObjectInputStream object.
# Java reflection mechanism
Http://blog.csdn.net/liujiahan629629/article/details/18013523 (easy to understand at a glance to understand)
Http://www.cnblogs.com/rollenholt/archive/2011/09/02/2163758.html
The JAVA reflection mechanism is in the running state. For any class, all attributes and methods of this class can be known. For any object, can call any of its methods and attributes. This kind of information obtained dynamically and the function of dynamically calling methods of objects is called the reflection mechanism of java language.
The Java reflection mechanism mainly provides the following functions: to judge the class to which any object belongs at runtime; to construct the object of any class at runtime; judge the member variables and methods of any class at runtime; call the methods of any object at runtime; generate a dynamic proxy.
Class
Class is the origin of the Reflection story. As we all know, Java has an Object class, which is the root inheritance of all Java classes. It declares several methods that should be rewritten in all Java classes: hashCode (), equals (), clone (), toString (), getClass (), etc. GetClass () returns a Class object.
The Class is very special. It inherits from objects like general classes. In fact, it is used to express the classes and interfaces when Java is running. It is also used to express enum, array, primitive Java types (boolean, byte, char, short, int, long, float, double) and keyword void. When a class is loaded, or when the defineClass () of the loader (class loader) is called by JVM, JVM automatically generates a Class object.