• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

transient modifier

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can transient modifier be specified for a static variable?
Acc.to mughal,transient modifier should not be specified to a static variable,as they don't belong to a class.
I did write a code using both modifiers and it compiles and runs without any problem.
Iam a little confused,pl.clarify.
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"should not be" is different than "can not be" --
Transient shouldn't be applied to a static variable because it does not belong to the class... and when you serialize an object, the static variables are not serialized anyway -- so marking one as transient would be silly.
If the book said "Transient can not be applied to static variables", you'd get a compiler error.
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess he means that because static fields are not going to be serialized, it is of no use declare them as transient.
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Geetha
A transient variable is one that is not stored as part an objects persistent state. Since static varaibels are not serialized anyway
transient does not apply to them. Compilers will allow you to do since it doesn't make any difference one way or the other.
hope that helps
 
geetha nagarajan
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for ur replies.
Read it as "can't be " ,from the book and got confused.
Got it now.
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
whew -- look at those response times "11:43", "11:44", "11:45" -- talk about service
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is even better. All the responses agree!
[ June 27, 2002: Message edited by: Jose Botella ]
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I type slower....
Actually, I type too quickly then have to go back and fix my mistakes so it's readable.
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jose Botella:
What is even better. All the responses agree!


nah... what's even better is that I was first!!
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Just for the info "Transient" and "volatile" are not mentioned in the objectives of the certification exam .
RHE page no 80.
Thanks
Praveen.
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but they can ask you if transient or volatile are java keywords. So, keep an eye on them!
Francisco
 
reply
    Bookmark Topic Watch Topic
  • New Topic