wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is transient allowed with static? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Is transient allowed with static?" Watch "Is transient allowed with static?" New topic

Is transient allowed with static?

Louie van Bommel
Ranch Hand

Joined: Aug 17, 2004
Posts: 76
1. Can a variable be transient if it is static?
2. If so, why? As far as I know java.io Object writing routines only write out instance variables, and not class variables. Aren't objects serialized without their static variables?
Thomas De Vos
stable boy
Ranch Hand

Joined: Apr 12, 2003
Posts: 425
Very interesting question.

Class variables (static) can be declared as transient, however class variables are not serialized and de-serialized. Only the persistence state of the object will be serialized, class variables will be re-created or intialized when the object is constructed after the de-serialisation process.

I recommend using the keyword transient for class variables, this makes it very clear to the programmer of the class that this variable will not be serialized.

Try your free <a href="http://www.javacertificate.com" target="_blank" rel="nofollow">SCJP 1.4</a> certification centre.<br />Try your free <a href="http://www.j2eecertificate.com" target="_blank" rel="nofollow">SCWCD</a> certification centre.<br />Try your free <a href="http://www.ejbcertificate.com" target="_blank" rel="nofollow">SCBCD</a> certification centre.<br />Try your <a href="http://www.webspherecertificate.com" target="_blank" rel="nofollow">Websphere (Test 285) </a> certification centre.<br />Try your <a href="http://www.j2mecertificate.com" target="_blank" rel="nofollow">SCMAD</a> certification centre. (New)<br /> <br /><a href="http://blogs.javacertificate.com" target="_blank" rel="nofollow">Java/J2EE Certification Blogging</a>
Tom Tolman
Ranch Hand

Joined: Sep 02, 2004
Posts: 83
Can you IO the class itself?
I agree. Here's the link: http://aspose.com/file-tools
subject: Is transient allowed with static?
It's not a secret anymore!