What are Transient and Volatile Modifiers?

Transient and volatile are not data types, they are modifiers. The transient keyword is used to indicate that an attribute should not be serialized when the object that contains it is serialized. The process of serialization refers to the transformation of an object into a stream of bytes. You usually do this to save off an object to disk or to send it across a network. Some classes are not serializable, such as a database connection, and they should be marked as transient when serializing an object that contains them in its state.

If a variable is declared volatile, then additional constraints apply to the operations threads that use the variable.
 
Volatile is a access modifier that informs to the compiler that the variable with this modifier can be changed unexpectedly by other elements of the program. In multithreading environment, one or more threads can share the same instance variables. Each thread can have its own copy of volatile variable. The real copy or the master copy of the variable is updated at times.
 
Volatile is a access modifier that informs to the compiler that the variable with this modifier can be changed unexpectedly by other elements of the program. In multithreading environment, one or more threads can share the same instance variables. Each thread can have its own copy of volatile variable. The real copy or the master copy of the variable is updated at times.

Fastmailsender
 
Back
Top