hi everybady,
i want to know, what is the use of transient, valatile keywords in java
and what is the use of serializable interface?
where and how we preserve the state of the object?
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
hi everybady,
i want to know, what is the use of transient, valatile keywords in java
and what is the use of serializable interface?
where and how we preserve the state of the object?
Transient means something is invisible to serialization.
Volatile information can be found at Java theory and practice: Managing volatility
Serializable is a marker interface to mark a class as serializable.
You can preserve the state of an object by using some sort of persistence like a database or file.
Here is an interface for this thread.
public interface Googleable { public List<GoogleResults> search(final String query); }
// Json
chinni (October 20th, 2009)
Transient is keyword, it is member variable of the class. This variable not persist when an object are stored or Serialized.
Serialization is an interface by which you can save the state of an object by converting it to a byte stream. Objects are passing through the network in byte format. This is Usage of Serialization interface.
Serialization is a way to store or transmit Java objects. Since objects refer to other objects, serialization recursively saves the "entire" object. Serialized objects can be saved to a disk file or sent over a communications link. "Reading" the result is then called deserialization, where the original object is reconstructed. If the object is stored to a disk file, the file is readable via Java, but nothing else.
Transient is something you use to tag a field that you do not want serialized. The simplest case would be a field that you plan to recompute each time, such as a sequence number, or a time field. If this value wouldn't be the same or make sense the next time you deserialize a class you could should use transient. Transient can also be used to tag a reference field so that serialization ignores this object. You might want to do this to reduce the amount of serialized data.
Volatile has nothing to do with serialization, but does have something to do with synchronization and threading.
Tom