Results 1 to 3 of 3
  1. #1
    Deepa is offline Member
    Join Date
    Nov 2008
    Rep Power

    Default Transient & Volatile

    Any1 plz explain the difference between Transient & volatile in java with sample coding

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    Java Code:
    * Note that the volatile and final keywords are not used on the same variable.
    * volatile and transient keywords are used on a variable, together as though
    * something could be transient and volatile, which they can. The word volatile
    * origninally came from work where a device may change a variable, independent
    * of the code. transient says to the compiler, do not save this in serialization.
    public class TransientDemo
        private static transient final Long startTime = new Long(currentTimeMillis());
        public static volatile transient long anotherTimeMillis;
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    Transient means that when an object is serialised this variable will not be serialised with it.

    Volatile means that, in threaded programs, the "base" version of the variable will be checked before every access to the thread local version. It is just one more way of ensuring consistent values between threads (but should not be used alone, it is not a replacement for syncronization).

Similar Threads

  1. Keyword : volatile
    By peiceonly in forum Advanced Java
    Replies: 13
    Last Post: 11-17-2010, 12:47 PM
  2. Transient vraible
    By serjant in forum Advanced Java
    Replies: 9
    Last Post: 11-10-2008, 02:13 PM
  3. use of volatile
    By venkatallu in forum New To Java
    Replies: 3
    Last Post: 09-23-2008, 09:59 PM
  4. Demonstration of the transient keyword
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 11:09 PM
  5. transient keyword
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-11-2007, 10:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts