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
What is Enum in Java?
What is class??
Explain the difference between jvm and jre?
Why is an interface be able to extend more than one interface but a class can’t extend more than one class?
What are the Class Libraries ?
How to calculate the length of a singly linked list in java?
What is the use of coding?
What is identifier with example?
What is return data type?
Is nan false?
Can we override the private methods?
What is constructor chaining and how is it achieved in java?
How do you delete a list in java?
Can we convert stringbuffer to string?
Can I learn java in 3 months?