my dog learned polymorphism*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "transient" Watch "transient" New topic
Author

transient

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

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:
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).]
 
wood burning stoves
 
subject: transient
 
Similar Threads
transient variable?
Doubt regarding ejbPassivate()
how to exclude a class member from hibernate mapping?
transient variable
making a mostly anonymous Comparator be Serializable