A static variable is not a part of object state and hence it won't participate in serialization due to this declaring static variable as transient there is no use.
Every final variable get value at compile time where as normal variable get value at run-time.
Final variable will be participated in serialisation directly by value hence declaring a final variable as transient there is no impact.
We can serialized any number of file but in which order we have seralized in the same order we have only to deseralized.
i.r serialization and deseralization order must be maintain.
Order of serilalization would be like this,if you are not aware of this
Object o = ois.read()
if(o instanceOf Dog)
Dog d = (Dog)o
if(o instanceOf Cat)
Cat d = (Cat)o
if(o instanceOf Rat)
Rat d = (Rat)o
class Dog {
Dog d = new Dog();
}
Class Cat {
Rat r = new Rat();
}
Class Rat {
int j =0;
}
In serialization, everything is controlled by JVM, not a programmer, It is also possible to save the total object to the file and it is not possible to save part of the object, which may create performance problem to overcome this problem we should go for externalization.The main advantage of externalization over serialization is everything is taken care by programmer and JVM doesn't have any control based on our requirement we can save total or part of the object which improved system performance.
To provide the externalizable ability for any java class must have to implement the Externalizable interface.That interface has two methods WriteExternal and ReadExternal
The Externalizable(1.1) interface is the child method os serializable(1.1) interface.
Account object has so many properties i want to do serialization externalization
Case 1: =
If a child doesn't implement serializable we can serialize child class object if parent class implement serializable interface.i.e serializable nature is inherited from parent to child.
hence if the parent is serializable every child is serializable.
Object class doesn't implement serializable interface.
Case 2:=
Even though parent class doesn't implement serializable we can serialize child class if child implements serializable interface.
At the time of serialization, JVM will check if any variable inheriting from a non-serializable parent or not if yes the JVM ignores the original value and save default value to the file.
At the time of deserialization, JVM will check if any parent class non-serializable or not if any parent is non-serializable then JVM will execute instance control flow for every and share instance variable to the current object
Every non-serializable should compulsorily contain no argument constructor it may be default constructor generator to compile or customized constructor explicitly provided by programmer otherwise we will get a runtime constructor invalid class exception.
Every final variable get value at compile time where as normal variable get value at run-time.
Final variable will be participated in serialisation directly by value hence declaring a final variable as transient there is no impact.
We can serialized any number of file but in which order we have seralized in the same order we have only to deseralized.
i.r serialization and deseralization order must be maintain.
Order of serilalization would be like this,if you are not aware of this
Object o = ois.read()
if(o instanceOf Dog)
Dog d = (Dog)o
if(o instanceOf Cat)
Cat d = (Cat)o
if(o instanceOf Rat)
Rat d = (Rat)o
class Dog {
Dog d = new Dog();
}
Class Cat {
Rat r = new Rat();
}
Class Rat {
int j =0;
}
In serialization, everything is controlled by JVM, not a programmer, It is also possible to save the total object to the file and it is not possible to save part of the object, which may create performance problem to overcome this problem we should go for externalization.The main advantage of externalization over serialization is everything is taken care by programmer and JVM doesn't have any control based on our requirement we can save total or part of the object which improved system performance.
To provide the externalizable ability for any java class must have to implement the Externalizable interface.That interface has two methods WriteExternal and ReadExternal
The Externalizable(1.1) interface is the child method os serializable(1.1) interface.
Account object has so many properties i want to do serialization externalization
Case 1: =
If a child doesn't implement serializable we can serialize child class object if parent class implement serializable interface.i.e serializable nature is inherited from parent to child.
hence if the parent is serializable every child is serializable.
Object class doesn't implement serializable interface.
Case 2:=
Even though parent class doesn't implement serializable we can serialize child class if child implements serializable interface.
At the time of serialization, JVM will check if any variable inheriting from a non-serializable parent or not if yes the JVM ignores the original value and save default value to the file.
At the time of deserialization, JVM will check if any parent class non-serializable or not if any parent is non-serializable then JVM will execute instance control flow for every and share instance variable to the current object
Every non-serializable should compulsorily contain no argument constructor it may be default constructor generator to compile or customized constructor explicitly provided by programmer otherwise we will get a runtime constructor invalid class exception.
EmoticonEmoticon