Keywords—keywords modifying methods, classes, attributes and variables (9 in total)

1、static

Static, attributes and methods can be modified with static, directly use the class name, attribute and method name. Only inner classes can be modified with the static keyword, and the call is directly made with the class name. The inner class class name is used for the call. static can exist independently

2、final

Both methods and classes can be modified with final; final modified classes cannot be inherited; final modified methods cannot be overridden by subclasses. The definition of constants: final modified attributes are constants.

3、synchronized

Only one thread can be executed at a time. Another thread must wait for the current thread to execute the code block before executing the code block.

4、transient

The purpose of the transient keyword is to implement the Serilizable interface, and add the keyword transient before the attributes that do not need to be serialized. When the object is serialized, this attribute will not be serialized to the specified destination (local disk).

Reference article: Java serialization-keyword transient

5、volatile

  Once a shared variable (class member variable, class static member variable) is modified by volatile, then it has two layers of semantics:

  1) Ensure the visibility of operations on this variable by different threads: when a shared variable is modified by volatile, it will ensure that the modified value will be updated to the main memory immediately, and when other threads need to read it, it will Go to the memory to read the new value. The visibility of ordinary shared variables cannot be guaranteed, because after ordinary shared variables are modified, it is uncertain when they will be written to the main memory. When other threads read, the memory may still have the original old value at this time, so Visibility cannot be guaranteed.

  2) Reordering instructions is prohibited.

Reference article: Java concurrency-volatile keyword

6、super

常见public void paint(Graphics g){super.paint(g); ··· }

7、this

Call the method in the current class (representing the object that calls this method) this.addActionListener(al): etc.

8、native

local

9 、 strictfp

Strict and precise

Guess you like

Origin blog.csdn.net/sanmi8276/article/details/112789349