Monday, March 29, 2010

Diff between transient and volatile variables

Transient variable:
A transient variable is a variable that may not be serialised.

Trying to put a non-serializable variable in a serialisible class,we can use transient modifier ,so that
the jvm skips the transient variable ,and make that class as serializable class

Volatile variable:
The volatile modifier tells the JVM that a thread accessing the variable must always reconcile its own private copy of
the variable with the master copy in memory. It can be apply only to instance variables.
Serialization:

"In computer science, in the context of data storage and transmission, serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file, a memory buffer, or transmitted across a network connection link to be "resurrected" later in the same or another computer environment.[1] When the resulting series of bits is reread according to the serialization format, it can be used to create a semantically identical clone of the original object. For many complex objects, such as those that make extensive use of references, this process is not straightforward." says Wikipedia.

Java provides such a mechanism, called object serialization. A so-called serialized object is an object represented as a sequence of bytes that includes the object’s data as well as information about the object’s type and the types of data stored in the object. After a serialized object has been written into a file, it can be read from the file and deserialized—that is, the type information and bytes that represent the object and its data can be used to recreate the object in memory.

source: http://www.deitel.com/articles/java_tutorials/20050923/IntroductionToObjectSerialization.html

No comments:

Post a Comment