Transient State of an object can be saved (write to any file) if the class
implements java.io.Serializable interface. In this case all of the field's value
will be saved. If we want any of the field's state must not be saved then we
have to modify that field by transient modifier. For example:
public class SerialDemo implements
java.io.Serializable
{
String name;
double salary;
transient int dob;
}
When we serialize the object of this class then name and salary field's value
will be saved but the value of dob will not be saved.
Volatile: In a multithreaded program sometimes two or more threads share
same variable. For efficiency each thread keeps its own private copy of the
shared variable and work on it. If you want to restrict the thread from
using own private copy of the variable and let them use master copy of the
shared variable then modify variable using volatile modifier. In
short we can say that volatile modifier can not be cached by the threads.
I Tried Google IT Support Professional Certificate on Coursera and It's
Awesome
-
[image: Is Google IT Support Professional Certificate Worth It]
Hello guys, if you want to start your career in the IT support field and
looking for resour...
1 day ago
No comments:
Post a Comment
I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.