• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

tell me what is transient( I know static etc)

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am curious what is transient is.
Is there a real good use of using this in Java context.
 
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Transient only applies to variables. The reason to make a variable transient is to not allow them to be part of thier persistent state. What that means is a transient variable will not be saved if you were to write the object out to a text file or something like that. The reason you may want to do this is for security reasons, salaries, credit card numbers, etc...
So, transient variables relate directly to Serializble class. There has been some confusion as to whether a transient variable can be static or not. A transient variable can be static, but since the only reason you use transient variable is to prevent them from being part of the persistent state, and static variables are not kept as part of the persistent state, doing so is redundant. If the variable is going to be static, you don't need to make it transient also. You can, but it doesn't have any effect.
Hope this helps some.
Bill

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bill,
Thanks for the info.
I am getting one more question. If we declare a variable as static with in a class and not as transient, I can not save the static variable while saving the object.
ie when saving situation arises for a object, do I need to define the variable as "transient static" or just "static" is sufficient.
 
bill bozeman
Ranch Hand
Posts: 1070
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you declare it as static then you can't save it, correct. So in that case you don't need the transient modifier. You can put it there, but it is just extra words that don't really do anything. But if you want to explicitly say, this is a transient variable, you can do so, like I said, it just has no real effect on static variables.
 
reply
    Bookmark Topic Watch Topic
  • New Topic