• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

transient

 
umang bhartia
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi every 1
I wanted to know something about transient.i know that only data member can be declared as transient. But I wanted to know as to when it is used and how? Please if possible help me out of this.
thank u
 
Ira Jain
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
A transient variable is used when an instance variable 's value need not be stored when its object is stored .
An example of it would be-
class A implements Serializable{
transient int time;
String year;
}
Now since the time is going to be different when it is restored there is no point in saving it while year will be the same.(ie if we don't restore it next year).

Hope it helps u .Please ask again if it is not clear.
Ira
------------------
 
Serge Plourde
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Umang,
If there is some data that you want to avoid to automatically write to a DataOutputStream, then you declare that member transient. Such data may be sensitive data such as password or credit card numbers etc...
You have some sample code, with topic discussion, at the following JavaRanch link:
http://www.javaranch.com/ubb/Forum24/HTML/004765.html

------------------
Hope this helps.
Have a good day.
[This message has been edited by Serge Plourde (edited October 13, 2000).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic