Two Laptop Bag
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes transient Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "transient" Watch "transient" New topic


umang bhartia
Ranch Hand

Joined: Sep 29, 2000
Posts: 60
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

Joined: Sep 06, 2000
Posts: 70
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.
Serge Plourde
Ranch Hand

Joined: Jun 23, 2000
Posts: 140
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:

Hope this helps.
Have a good day.
[This message has been edited by Serge Plourde (edited October 13, 2000).]
I agree. Here's the link:
subject: transient
It's not a secret anymore!