Meaningless Drivel is fun!
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "variables difference" Watch "variables difference" New topic

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.

amit bhadre
Henry Wong

Joined: Sep 28, 2004
Posts: 20517

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.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: variables difference
It's not a secret anymore!