This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes variables difference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "variables difference" Watch "variables difference" New topic
Author

variables difference

amit bhadre
Ranch Hand

Joined: Jan 23, 2006
Posts: 124
What is the difference b/w transient and volatile variable?


Thanks advance who ever answers this question.


regards
amit bhadre
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18545
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: variables difference
 
Similar Threads
Array Initilaize
Clarification
interview question
WA #1.....word association
Why anonymous posts are allowed in this forum ?