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
What is the use of predicate in java 8?
What is a method declaration?
How does linkedhashmap work in java?
What is the difference between an argument and a parameter?
What does int [] mean in java?
Explain a situation where finally block will not be executed?
what is thread? What are the high-level thread states? : Java thread
What are the three parts of a lambda expression?
What is meant by object oriented programming – oop?
What is java and its types?
what is the purpose of the runtime class?
2) Suppose there are 5 directories having lot of files (say txt files) in each directory. 2 things :- 2.1) You want to search for filenames which have a particular pattern. 2.2) Out of these filtered files you want to search for a particular keyword or a search string. How can you achieve this?
How will you print number in reverse (descending) order in BST.
Why we do exception handling in java and how many types of exceptions are there?
What is finalize method?