why to use transient variables when static variables can be
used for Serialization
Answers were Sorted based on User's Feedback
Answer / lenina
only non static and non transient variables can be serialized.
if we want a variable to be instance variable,but the
variable is non serializable variable, then we declare that
variable as transient. here exactly we can make use of
transient.
Is This Answer Correct ? | 26 Yes | 7 No |
Answer / ram
Both static & Transient are may not be serialized.
Static means one per class not one per object. Static
variables are not saved and when an object is deserialized,
it will have whatever static variable its class currently
has. Don’t make serializable objects dependent on a
dynamically-changing static variable. It might not be the
same when the object comes back.
Transient variables are given a value of NULL for object
references and defaults (0, false, etc) for primitives.
Is This Answer Correct ? | 12 Yes | 4 No |
Answer / priyanjan
static variables can also serialized but is a very
cumbersome process. Transient keyword prefixing any
variable states that the varible does serialized but its
state i.e. value of the varible, does not serialize.
Is This Answer Correct ? | 10 Yes | 7 No |
Answer / yogesh
A transient variable is a variable that may not be serialized.
Is This Answer Correct ? | 4 Yes | 6 No |
can you create interface instance ?
what is the use of bean managed and container managed with example?
Is an object null?
How many bits is a char?
what is difference between type 4 driver and type 1 driver?
2 Answers CMC, CTS, IBM, JK Technosoft, Napier Healthcare,
How garbage collection is done in java?
What are the benefits of operations in java?
What is difference between string and stringbuffer?
To obtain design information about an object, which class in used?
What are the two ways in which thread can be created?
What is final, finally, finalize?
What is bigger kb or mb?