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 default size of arraylist in java?

559


How to convert string to char and vice versa?

518


Explain the protected field modifier?

597


What is a cup of java?

561


Which one of the following suits the description of a string better: derived or primitive?

514






Can java program run without jre?

571


What is jit and its use?

586


What is difference between path and classpath in java?

487


what are three ways in which a thread can enter the waiting state? : Java thread

578


What happens when I use / and % with a negative numerator?

538


What is singleton class in java and how can we make a class singleton?

575


if u open login & logout ,how can udisplay the timelogin & logout members ?

1756


What is static import?

602


How do you use nextline in java?

505


I want to control database connections in my program and want that only one thread should be able to make database connection at a time. How can I implement this logic?

641