Final static deep parsing, finalstatic
function test(){ var a = b = 10; } test( ); alert(b);
As mentioned in the previous blog, the last output is 10. The reason for ambiguity is the relationship between global variables and local variables. Follow this topic and talk about this part in java. This section describes the total -- minute -- total structure.
Refer to blog:
Static detailed analysis
Is the instance constructor static?
Total: java does not have the concept of global variables. There are only local variables and member variables.
Java does not have the concept of "global variables. Instead, we have the concept of "static. 1. Modify the member variables in static mode. 2. static modifier member method. 3. static modifier static code block.
The static modified member variables and member methods are independent of any object in the class. That is, it is not dependent on the instance of the class and is shared by all instances of the class. As long as the class is loaded, the Java Virtual Machine can find them in the Method Area of the runtime data Zone according to the class name. Therefore, a static object can be accessed before any of its objects without applying any objects.
A.
Next, compare final.
The Java. lang. String class cannot be inherited because it is modified by final. 1. final modifier class; 2. final modifier; 3. final modifier variable (member variable and local variable ).
Final modifier class. The class cannot be inherited. This is the case for the String class. The final modifier locks the method to prevent its class from modifying its meaning. Final modifier variables include modifier basic data type variables and application type variables. The value of a variable of the basic data type cannot be changed after modification. variables of the reference type cannot point to another object after initialization, but can change the content of the current object.
Different opinions:
1 .(National fortune) You cannot call non-static methods within the static method, which is the opposite.
2. The purpose of static is to facilitate calling (methods/variables) without creating an object ). Methods or variables modified by the static keyword do not need to be accessed by objects. As long as the class is loaded, the class name can be used for access.
3. for static methods, there is no this, because it is not attached to any object. Since there are no objects, there is no such thing as this.
4. In static methods, non-static member variables and non-static member methods of the member class cannot be called because non-static member methods/variables must depend on specific objects.
5. Non-static member methods and non-static member variables cannot be accessed in static methods, but static member methods and variables can be accessed in non-static member methods.
6. Even if it is not displayed as static, the class constructor is actually a static method. But why is there a constructor? Can this be used to access member variables ?? Blog
Supplement: Although static member variables are independent of objects, they do not mean they cannot be accessed through objects. All static methods and static variables can be accessed through objects (as long as they have sufficient access permissions ).
7. the difference between static variables and non-static variables is that static variables are shared by all objects and have only one part in the memory. They are initialized only when the class is first loaded. Instead of static variables, they are owned by objects. They are initialized when an object is created, and there are multiple copies.
8. static code block, used to optimize program performance. When a class is loaded for the first time, each static block is executed in the order of static blocks, and only once. (It is executed only once during class loading.)
9. In Java, remember that static is not allowed to be used to modify local variables. Don't ask why. This is the Java syntax.
10. The String class in Java is a final class.
11. When a class is modified with final, it indicates that the class cannot be inherited. Note that all member methods in the final class are implicitly specified as final methods.
12. for a final variable, if it is a basic data type variable, its value cannot be changed once it is initialized; if it is a reference type variable, after initialization, you cannot point it to another object.
13. The reference variable modified by final cannot point to other objects once the value is initialized. The content of the object to which the referenced variable points is variable.
14. In many cases, it is easy to confuse static and final keywords. static acts on member variables to save only one copy, while final is used to ensure variable immutability.
Public class Test {public static void main (String [] args) {MyClass myClass1 = new MyClass (); MyClass myClass2 = new MyClass (); System. out. println (myClass1. I); System. out. println (myClass1.j); System. out. println (myClass2. I); System. out. println (myClass2.j);} class MyClass {public final double I = Math. random (); public static double j = Math. run this code and you will find that the two j Values printed each time are the same, while the I values are different. Here we can know the difference between final and static variables.
Java basics:
Java internal class
HashMap details
Algorithm:
Sorting Algorithm Summary
Improved String Matching Algorithm KMP