• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variables difference

 
amit bhadre
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference b/w transient and volatile variable?
 
Henry Wong
author
Marshal
Pie
Posts: 21022
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A transient variable is an instance variable that will not be processed during serialization of the object that it is part of. This means that when the object is deserialized, the variable will have a default value, instead of the original value.

A volatile variable is a variable that will be accessed by multiple threads at the same time. The JVM will not make cache copies of the variable. Furthermore, the JVM will also make sure that reads and writes to the volatile variable is atomic -- which for longs and doubles is not normally the case.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic