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 early binding and late binding in java?

593


Why 1 is not a prime number?

553


What about static nested classes in java?

588


What are keyboard events?

608


What is __ init __ functions?

544






What is qms certification?

520


What is the tradeoff between using an unordered array versus an ordered array?

657


What is meant by string is immutable?

515


How to perform binary search in java?

570


Can an anonymous class be declared as implementing an interface and extending a class in java programming?

646


What is covariant return type?

639


What is the difference between import java.util.date and java .util?

566


What are the access modifiers in java?

584


how does multithreading take place on a computer with a single cpu? : Java thread

688


What is illegal identifier in java?

529