• Post Reply Bookmark Topic Watch Topic
  • New Topic

transient and volatile variables  RSS feed

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please do resolve my query

generally what does state of the object mean? and also about what is meant by a referance variable(is it a class variable?)

I don't understand what are transient and volatile variables.please convey in a manner so that i could understand
(i am just a beginner just have a simple overview about java)
 
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's a state. Let say you have an Object Tea Cup. It's state would be volume, empty/full/half, colour, etc. basically it would be the way in which you can identify the tea cup. Similarly in Objects the state of the object would be the value/data that is stored in the objects that represent the object. So for example : For an object user, the state would be username, first name, last name, etc.

Reference variables : I assume you have some basic idea about java / any programming language. When you say String str = new String("hi!"); then str is the reference variable. Basically reference variable is a storepoint wherein you can save a reference/address to get back to an object you created.

Transient and volatile : You can only mark variables as transient or volatile.

A transient variable is one which would not be serialized. That is, when you try to write the state of an object it would not be saved. For example for our tea cup example, one could make the colour of tea cup as transient.

A volatile variable is one which you think can be accessed by multiple threads and thus ask the JVM to take extra precautions while dealing with it by marking it as volatile.

I would suggest that you read up a bit on these.
 
author
Sheriff
Posts: 8954
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd say that this isn't really a beginner question. Transient and volatile are good things to know later on, but not so important until you really get your fundamental Java and OO concepts well understood.
 
sree visu
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you so much Anupam Sinha for clearing my doubts
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!