Tuesday, April 20, 2010

Static vs Transient variables

Static variables
  • Static variables are class variables.
  • Static variables can be serialized.
  • static modifier applies to static variables.
       class TestClass{
          static int testVariable;
          . . .
      }

Transient variables
  • Transient variables are member or instance variables of class.
  • Transient variables can not be serialized.
  • transient modifier applies to transient variables.
       class TestClass{
          transient int testVariable;
          . . .
      }

12 comments:

  1. yes.....got it!
    I have a question regarding volatile modifier.
    I heard it can b used in timer applications,but
    even after reading much about it i am not able to understand correctly.
    Can u please explain with appropriate example..

    ReplyDelete
  2. Hi Kapish,

    The volatile is not necessary to used only in timer applications. The below post may help you to understand more about volatile modifiers.

    http://sharad-java-j2ee-interview-questions.blogspot.com/2010/05/volatile-modifiers-in-java.html

    If you still have problem please let me know.

    Have a great day :)

    ReplyDelete
  3. Hi my name is Munisekhar,

    I want know the difference between transient and static in serilization process.please help me

    ReplyDelete
  4. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Devops Training in Bangalore
    Microsoft azure training in Bangalore
    Power bi training in Chennai

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Such a great blog.Thanks for sharing useful information......
    Applications of Hadoop
    Hadoop Applications

    ReplyDelete
  7. This post is so interactive and informative.keep update more information...
    Android Training in Tambaram
    Android Training in Chennai

    ReplyDelete