Home
»
Interview Questions Core Java
» Why should we declare the variable with " transiant " keyword... ? what is the use of "transient" keyword in JAVA?
the transient keyword is applied to only variables, if we want to not participate the variables in serialization then that variable is declared as transient . for example String userName="abcd"and String password="abcd" we declared in a class and that class is implements the Serializable interface, while we transfer the Objects through network, after we deserialize the class it shows the original value. suppose if we declare the password as ''transient", then after we deserialize the objects, it shouws String default value(i.e., null) that means , default variable values... if int i=10, after deserialize the object it shows Zero....
the transient keyword is applied to only variables, if we want to not participate the variables in serialization then that variable is declared as transient .
ReplyDeletefor example
String userName="abcd"and
String password="abcd"
we declared in a class and that class is implements the Serializable interface, while we transfer the Objects through network, after we deserialize the class it shows the original value.
suppose if we declare the password as ''transient", then after we deserialize the objects, it shouws String default value(i.e., null) that means ,
default variable values... if int i=10, after deserialize the object it shows Zero....