• 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

meaning of keywords static, transient, volatile

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Please tell me the clear distinction among the following keywords defined by java.
=>static
=>transient
=>volatile
Thanks
Maghvendra.
 
Ranch Hand
Posts: 412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
static: you can have static variables as well as methods. both static variables and methods belong to the class and not to any particular instance of that class.(i am actually retyping this, sheriff, please look into this. this portion was lost during my first edit.)
eg:-

you access them like,

transient: this keyword prevents Serialization when used with a variable. that is it prevents that particular field which has been declared as transient not to be saved to the disk.

------------------
Raghav.
[This message has been edited by Raghav Sam (edited June 20, 2001).]
[This message has been edited by Raghav Sam (edited June 20, 2001).]
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maghvendra,
volatile is a keyword used in threads. Basically java lets individual threads hold their own copy of varaibles while they are executing. For narmal variables used in threads the threads copy is checked against a master copy only when objects that have that variable are locked or unlocked and other key times. Using volatile tells the compiler to check the threads copy against the master copy everytime the thread accesses the variable.
That was a quick explaination, for more details go here: http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#36930
hope that helps

Dave
 
This will take every ounce of my mental strength! All for a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic