InterviewSolution
| 1. |
What Is The Difference Between Transient And Volatile Variable In Java? |
|
Answer» TRANSIENT: In Java, it is used to specify the VARIABLE is not being serialized. Serialization is a process of SAVING an object’s state in Java. When we want to persist and the object’s state by default, all instance VARIABLES in the object are STORED. In some cases, if we want to avoid persisting few variables because we don’t have the necessity to transfer across the network. So, declare those variables as transient. If the variable is confirmed as transient, then it will not be persisted. Transient keyword is used with that instance variable which will not participate in the serialization process. We cannot use static with a transient variable as they are part of the instance variable. Transient: In Java, it is used to specify the variable is not being serialized. Serialization is a process of saving an object’s state in Java. When we want to persist and the object’s state by default, all instance variables in the object are stored. In some cases, if we want to avoid persisting few variables because we don’t have the necessity to transfer across the network. So, declare those variables as transient. If the variable is confirmed as transient, then it will not be persisted. Transient keyword is used with that instance variable which will not participate in the serialization process. We cannot use static with a transient variable as they are part of the instance variable. |
|