aspose file tools*
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 Spring in Action this week in the Spring 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: 18896
    
  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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: variables difference