• Post Reply Bookmark Topic Watch Topic
  • New Topic

Transient and Volatile Keyword in java  RSS feed

 
Ramki Sukumaran
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can any one tell me why transient and Volatile keyword is used in Java?

Regards
Ramki S
 
manish ghildiyal
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A variable declared as transient means that it won't be serialized when object is serialized.

Volatile keyword for a variable means that value of the variable is read directly from memory rather than from cache,
hence it helps in avoiding issues like non-visibility of changes made by simultaneous threads or what we call stale data issue.

Manish
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!