2020 at 9:11 on February 26

Class loader

https://blog.csdn.net/m0_38075425/article/details/81627349

 

The method defined interface defaults to public abstract type member variable type interface defaults to static Final public .

 

transient use Summary

1) Once the variables are modified transient, variable object persistence will no longer be part of the variable content after serialization can not gain access.

2) transient keyword can only modify variables, methods and classes can not be modified. Note that local variables can not be modified transient keyword. If the variable is a user-defined class variables, the class needs to implement Serializable interface.

3) modified transient key variables can no longer be serialized, regardless of whether a static variable is transient modification, not be serialized.

    We know that in Java object serialization can be achieved by implementing two interfaces, if Serializable interface is implemented, then all will be serialized automatically, if the implementation is Externalizable interface, there is nothing automatic sequence , it is necessary to manually specify the sequence of the variable writeExternal process, regardless of whether a transient is modified. Thus the output of the second example of the content is initialized variable content, not null.

 

Visibility, atomic and orderliness Java memory model.

Visibility:

  Visibility is a complex property because the visibility of error will always contrary to our intuition. In general, we can not guarantee thread can perform a read operation in a timely manner to see the value of other threads written, and sometimes simply impossible. In order to ensure visibility among multiple threads of memory write operations, you must use the synchronization mechanism.

  Visibility means visibility between threads, a thread modifies a state of another thread is visible. That is the result of a modification of the thread. Another thread can immediately see. For example: using volatile variables would have visibility. volatile variables are not allowed inside thread and reorder buffer that directly modify the memory. So the other threads are visible. But note here a problem, volatile only let him be content with a modified visibility, but can not guarantee that it is atomic. For example, volatile int a = 0; a ++ after a operation; this variable has a visibility, but still a ++ is a non-atomic operation, that is, this operation also exists thread-safety issues.

  In Java volatile, synchronized and the final realization of visibility.

Atomicity:

  Atom is the smallest unit in the world, has indivisibility. For example a = 0; (a non-long and double) This operation is indivisible, then we say that this operation atomic operation. Another example: a ++; this operation is actually a = a + 1; is divisible, so he is not an atomic operation. Non-thread-safe atomic operations there will be problems, we need to use synchronous technology (sychronized) to make it into an atomic operation. Operation is atomic, then we call it atomic. provides some of the atoms under the category of concurrent java package, we can understand the usage of these atoms class by reading the API. For example: AtomicInteger, AtomicLong, AtomicReference and so on.

  In Java and synchronized in lock, unlock operation guarantee atomicity.

Ordering:

  Java language provides two keywords volatile and synchronized to ensure orderly, volatile because of its own with "prohibit instruction reordering" of semantics, synchronized operation between threads is by "allowing only one variable at a time in the same thread lock its operation "rule obtained, the rules determine the synchronization holding two blocks of the same object lock can only be executed serially.

 

 

Automatic type conversion

Integer, real (constant), the mixing operation may be character data. In operation, to different types of data into the same type, then operation.

Transition from junior to senior.

Low ------------------------------------> high byte , Short , char -> int -> Long -> float -> Double           
 float there is no such case, since it is necessary to keep after the number F or f in the definition of type float.

static modifier

  • Static variables:

    The static keyword is used to declare static variables independent of the object, no matter how many objects a class is instantiated, it is only one copy of a static variable. Static variables also known as class variables. Local variables can not be declared as static variables.

  • Static methods:

    static keyword is used to separate the object of a static method declaration. Static methods can not use non-static variables class. Static method to get the data from the parameter list, the data is then calculated.

final method

final method in the parent class can be inherited by subclasses, but can not be overridden by subclasses.

The main purpose of the method is to prevent the final declaration of this method is modified.

 

Abstract method

Abstract no method is a method of implementation, the specific implementation of the method provided by subclasses.

Abstract methods can not be declared as final or static.

Any subclass inherits all the abstract class abstract methods of the parent class must implement, unless the subclass is also abstract class.

If a class contains a number of abstract methods, the class must be declared as an abstract class. An abstract class may not contain abstract methods.

Abstract method declarations end with a semicolon, for example: public abstract Sample (); .

 

 

The method of synchronized keyword to declare the same time can only be accessed by a thread

 

volatile modified member variable each time it is accessed threads are forced to re-read the value of the member variable from shared memory. Also, when members of the variable changes, a thread is forced to change the value written back to the shared memory. So that at any moment, two different threads always see the same value of a member variable.

 

 

 

0 is false, 1 as true

 

Difference throw keyword throws keyword (interview)

1.throw keyword for internal method represents a human error thrown.

2.throws keyword is used on a method declaration, clearly tell the user this abnormal method that may arise, while this method may not handle the exception.

Guess you like

Origin www.cnblogs.com/complain/p/12368921.html