serialization = writing values to a file
deserialization = reading values from a file
What kind of file extensions do you allow? Every time I attach a file here, I always get "file extension not allowed" error.
Please see 2 code segments in 2 separate posts after this due to 3000-character limit. Both code segments are tested and they both work.
They are adapted from
https://www.amazon.com/OCP-Certified-Pr ... entries*=0
and I own one hard copy book.
To run them, please do
javac ObjectStreamSample.java AnimalSerializable.java
followed by
java ObjectStreamSample
Now you said
The book also says any static variables or default initializations are ignored.Remember that static fields are never serialized....
In the 2nd code segment, createAnimalsFile() is used to serialize, i.e. to write values to a file, and getAnimals() is used to deserialize, i.e. to read values from a file.
Question 1
As you said, if the static fields are never serialized, i.e. values not written to a file, then how can we deserialize, i.e. read values from a file, by using getAnimals() method in the 2nd code segment?
Question 2
When you said "static fields are never serialized," did you mean ignoring all static fields in the process of serialization whether or not the static variables contain programmer-initialized values or the default values assigned to them by the compiler?
I'm simply trying to understand this concept. I have no other intention.
Thanks.
Schmichael