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 / jagan kumar(zylog systems ltd.

Transient
.........
Only variable can be declared as Transient, When
used as a Modifier in a variable Declaration it suggests
that a variable may not be return out when the class is
serialized

Volatile
.........
The keyword volatile can be used to declare
variables. The use of the keyword volatile in a variable
declaration suggests the compiler that multiple threads may
access the variable. Therefore the value of the variable
may change unexpectedly. A Compile time error will occur
declaring a variable both volatile and final.

Example for Volatile:
.....................

volatile int v = 0;
Thread 1:
v++;
Thread 2:
v--;

The questioners usually want the answer "v can only
be 0 after this code is run", because

volatile int v = 0;
Thread 1:
r1 = v;
r2 = r1 + 1;
v = r2;
Thread 2:
r3 = v;
r4 = r3 - 1;
v = r4;
So, if Threads 1 and 2 both read v and see the value
0, then Thread 1 will write 1 to it and Thread 2 will
write -1 to it. You are not guaranteed to see the value 0!

Is This Answer Correct ?    16 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the escape sequences in java?

978


How does indexof work?

892


What is nested interface?

958


How can constructor chaining be done using this keyword?

1208


what is abstract class in Java?

1069


Explain the concept of proper inheritance?

1011


What do u mean by variable?

990


What is Classloader in Java?

1129


Can singleton class be inherited in java?

937


What is the difference between method and means?

1016


How do you break a loop?

926


What is string [] java?

898


Why scanner is used in java?

1009


Can a class have 2 constructors?

848


What is a memory leak in java?

1014