why to use transient variables when static variables can be
used for Serialization
Answer Posted / 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 |
Post New Answer View All Answers
How many ways can you break a singleton class in java?
What are thread safe functions?
How will you reverse a link list without using recursion?
What is use of a abstract variable?
Why is stringbuffer not immutable?
What is anagram word?
Can we declare the static variables and methods in an abstract class?
What is the difference between Grid and Gridbaglayout?
Which one will take more memory: an int or integer?
What super () does in java?
How do you remove duplicates in java?
What does jre stand for?
Is java code slower than native code?
What is synchronization and why is it important in java programming?
What are different types of references?