why to use transient variables when static variables can be
used for Serialization

Answers were Sorted based on User's Feedback



why to use transient variables when static variables can be used for Serialization..

Answer / lenina

only non static and non transient variables can be serialized.

if we want a variable to be instance variable,but the
variable is non serializable variable, then we declare that
variable as transient. here exactly we can make use of
transient.

Is This Answer Correct ?    26 Yes 7 No

why to use transient variables when static variables can be used for Serialization..

Answer / 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

why to use transient variables when static variables can be used for Serialization..

Answer / priyanjan

static variables can also serialized but is a very
cumbersome process. Transient keyword prefixing any
variable states that the varible does serialized but its
state i.e. value of the varible, does not serialize.

Is This Answer Correct ?    10 Yes 7 No

why to use transient variables when static variables can be used for Serialization..

Answer / yogesh

A transient variable is a variable that may not be serialized.

Is This Answer Correct ?    4 Yes 6 No

Post New Answer

More Core Java Interview Questions

Explain the pointers in Java?

0 Answers   Aspire,


What is better- service oriented or batch oriented solutions?

0 Answers   Amdocs,


Where will it be used?

0 Answers  


Can we iterate through collection using for loop?

2 Answers   Rolta,


What are order of precedence and associativity, and how are they used?

1 Answers  






whats the diff between jsp and servlets?

9 Answers   HCL, TCS,


What is the difference between yield() and sleep()?

0 Answers  


What is the use of beaninfo?

0 Answers  


What is e java?

0 Answers  


Why chararray() is preferred over string to store the password?

0 Answers  


I have an HashMap object, which has with key and value pair. It has 10 keys and values in that object. Now the question is I want insert new key and value in middle or any where in that list but not at the end or at the top. Is it possible or not. If yes how can we achieve this one?

2 Answers   Huawei,


How many bits does a boolean take?

1 Answers  


Categories