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
Explain thread in java?
What is public static void main?
whatis Home interface and Remoteinterface? with example?
Is arraylist an object in java?
What are the disadvantages of object oriented programming?
How many arguments can a method have java?
Is java jre still free?
I want my class to be developed in such a way that no other class (even derived class) can create its objects. Define how can I do so?
What are different types of inner classes ?
How is it possible for two string objects with identical values not to be equal under the == operator?
Is hashset sorted in java?
Explain the difference between string, stringbuffer and stringbuilder in java?
What is command line argument in java?
What do you mean by aggregation?
How do you break a loop?