Static and final
Static modifier keywords, can modify variables, program block, class method;
When you define a static variable, the JVM allocates it to the memory heap, and all references to it will point to that address without reallocating the memory;
When modifying a program block (that is, writing the code directly in the static{...} , the virtual machine loads the code in the static block first, which is used primarily for system initialization;
When you modify a class method, you can call it directly from the class without needing to create a new object.
Final can only be assigned one time, modifying variables, methods, and classes,
When you define a final variable, the JVM assigns it to a constant pool, and the program cannot change its value; When you define a method, the method cannot be overridden in a subclass, and when you decorate a class, the class cannot be inherited.
Static and final use scopes: classes, methods, variables.
2. Distinction and Contact:
2.1.static meaning: Static, statically decorated methods and properties belong to any object that the class does not belong to the class.
2.2.static usage:
2.2.1.static can decorate "inner classes", methods, and member variables.
2.2.2.static "Cannot decorate the outer class", "cannot decorate the local variable" (because static is defined as the class level, so the local level variable is not static decorated).
2.3 Final Meaning: "Can only be assigned once".
2.2.final usage:
A 2.2.1.final decorated property that indicates that the property can only be assigned once, (1) The base type: The value cannot be modified, and (2) the reference type: The reference cannot be modified.
The 2.2.2.final decoration method, which indicates that the method cannot be overridden, but can be accessed by a quilt class if the method is not private type.
A 2.2.2.final decorated class that indicates that a class cannot be inherited.
3. Combined use of static final
3.1. Scope of application:
3.1.2. The intersection of the two ranges, so it can only be modified: member variables, methods, inner classes.
3.2. Meaning: Also the intersection of the two:
3.2.1. Method: A method that belongs to a class and cannot be overridden.
3.2.2. Member variable: A variable that belongs to a class and can be assigned only once.
3.2.3. Inner class: Belongs to an external class and cannot be inherited
Type modifiers, which can only be used to decorate a field, if an instance variable is declared with transient, its value does not need to be maintained when the object is stored. In other words, a member variable tagged with the transient keyword does not participate in the serialization process.