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


Please Help Members By Posting Answers For Below Questions

What is Enum in Java?

686


What is class??

762


Explain the difference between jvm and jre?

564


Why is an interface be able to extend more than one interface but a class can’t extend more than one class?

711


What are the Class Libraries ?

600






How to calculate the length of a singly linked list in java?

589


What is the use of coding?

526


What is identifier with example?

581


What is return data type?

563


Is nan false?

537


Can we override the private methods?

531


What is constructor chaining and how is it achieved in java?

575


How do you delete a list in java?

536


Can we convert stringbuffer to string?

568


Can I learn java in 3 months?

546