Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is Transient and volatile

Answer Posted / manodeep pandey

Java defines two interesting type modifiers: transient and
volatile. These modifiers are used to handle somewhat
specialized situations.

When an instance variable is declared as transient, then
its value need not persist when an object is stored. For
example:

class T {

transient int a; // will not persist

int b; // will persist

}

Here, if an object of type T is written to a persistent
storage area, the contents of a would not be saved, but the
contents of b would. The volatile modifier tells the
compiler that the variable modified by volatile can be
changed unexpectedly by other parts of your program. One of
these situations involves multithreaded programs. In a
multithreaded program, sometimes, two or more threads share
the same instance variable. For efficiency considerations,
each thread can keep its own, private copy of such a shared
variable. The real (or master) copy of the variable is
updated at various times, such as when a synchronized
method is entered. While this approach works fine, it may
be inefficient at times. In some cases, all that really
matters is that the master copy of a variable always
reflects its current state. To ensure this, simply specify
the variable as volatile, which tells the compiler that it
must always use the master copy of a volatile variable (or,
at least, always keep any private copies up to date with
the master copy, and vice versa). Also, accesses to the
master variable must be executed in the precise order in
which they are executed on any private copy.

Is This Answer Correct ?    5 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are JVM.JRE, J2EE, JNI?

1065


What does || || mean in math?

890


Write a program in java to create a doubly linked list containing n nodes.

925


How can constructor chaining be done by using the super keyword?

1055


What is length in java?

979


Which variables are stored in heap?

986


Why is java logo a cup of coffee?

1103


What are the two parts of a conditional statement?

928


What is super keyword explain with example?

1241


I want to persist data of objects for later use. What’s the best approach to do so?

890


Is ++ operator is thread safe in java?

913


Write a program based on Java script program.

1086


Can java list be null?

960


Can we convert integer to string in java?

1020


Can we have more than one package statement in source file ?

986