Why is transient modifier used and where in real life?

Many people disturbed me about the solution,some one help me.

Showing Answers 1 - 8 of 8 Answers

Hasan

  • Oct 24th, 2005
 

transient is modifier. It is used for a variable which is not to be serialized

  Was this answer useful?  Yes

Lavanya.G

  • Nov 3rd, 2005
 

Transient variable means not searializable.that mens we r forcefully making that variable as notserializable.

  Was this answer useful?  Yes

suppose a class have a variable 'password' is transient and this class implements serializable.When the object is passed remotly all the variables except password will get serializable.The value of transient password field will not become part of the serialized representation of the object. Consequently, it won't be transmitted in the byte stream to wherever the object is destined, and it won't be available to read when the object gets there.

The deserialized object will still have a password field, but the value will be null.

Transient is useful when you either don't need the value on the other end or you can reconstruct it from other information. If neither of those is true for you, then you shouldn't use transient for your password field.

  Was this answer useful?  Yes

sandhya

  • Nov 7th, 2005
 

if we use the key word transient before any variables it will work like a const.it means we cannot change the value and this variable can not be stored in a menory

  Was this answer useful?  Yes

Raja Chaithanya Bangaru

  • Nov 11th, 2005
 

In Java, all objects are not serializable.In distibuted environment,an object needs to be serializable.(serialization means writing the state of an object to a file using output stream so that it persists forever).

In the process of serialization of an object, some instances like Socket,Connection are not serializable.if some are not serializable,a serialization exception occurs when we try to serialize the object.To avoid that ,we use transient so that the instances with transient modifier are ignored.

  Was this answer useful?  Yes

Volatile modifier is being used in the field of multithreading because whenever all the threads access to a single variable ,they have their seperate copy of that variable and if they modifies the variable it won't change the actual variable in the memory and all the other thread will not have the changed value of the variable .this problem is shorted out by the use of volatile modifier

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions