If you declare an instance variable with transient, its value does not need to be maintained when the object is stored. For example:
Java code
-
class T
-
transient int A; //Do not need to maintain
-
int b; //need to maintain
-
}
here, if an object of the T class is written to a persistent storage area, the contents of a are not saved, but B's will be saved.
The volatile modifier tells the compiler that variables modified by volatile can be changed by other parts of the program. In multithreaded programs, sometimes two or more threads share an identical instance variable. Consider the efficiency issue, where each thread can save its own private copy of the shared variable. The actual copy of the variable is updated at different times, such as when entering the Synchronized method.
using STRICTFP to decorate classes or methods ensures that floating-point operations (and all cuts) are as accurate as earlier versions of Java. Cuts the exponent that affects only certain operations. When a class is STRICTFP modified, all methods are automatically modified by STRICTFP.
strictfp means fp-strict, that is to say, the meaning of the precise floating point. When a Java virtual machine makes a floating-point operation, if the STRICTFP keyword is not specified, the Java compiler and the runtime's expression on floating-point operations do so in an approximate way, so that the resulting results do not always satisfy you. Once STRICTFP is used to declare a class, interface, or method, the compiler and the runtime environment for the declared scope of Java are executed exactly as the floating-point specification IEEE-754. So if you want your floating-point arithmetic to be more accurate and not inconsistent with the results of different hardware platforms, then use the keyword STRICTFP.
you can declare a class, interface, and method as STRICTFP, but do not allow the STRICTFP keyword to be declared on methods and constructors in the interface, such as the following code:
1. Legal use of keyword STRICTFP
Java code
-
STRICTFP Interface A {}
-
-
Public STRICTFP class FpDemo1 {
-
STRICTFP void f () {}
-
}
2. How to use the error
Java code
-
Interface A
-
STRICTFP void f ();
-
}
-
-
Public class FpDemo2 {
-
STRICTFP FpDemo2 () {}
-
}
Once the keyword STRICTFP is used to declare a class, interface, or method, all floating-point operations within the scope declared by this keyword are accurate and conform to the IEEE-754 specification. For example, if a class is declared as STRICTFP, then all methods in the class are STRICTFP.
Keys:volatile
working with objects: Fields
Description: Because asynchronous threads can access fields, some optimizations do not necessarily work on fields. Volatile sometimes
can replace synchronized.
keys:transient
working with objects: Fields
Description: The field is not part of the object's persistent state, and the fields and objects should not be strung together.
Transient,volatile and STRICTFP keywords in Java