What is Serializing good for?
I'm currently reading through the SCJP 6 book and have reached Chapter 6, specifically, Serializing. For me, to grasp and understand something to its' fullest (relatively speaking, of course), I need to understand what it is good for, why it is used, and most importantly, when.
If you had used Serializing, could you tell me why you did so, and what it was for? I understand that you can save the state of an Object on the file system, I just don't understand where it could be used. Like saving a game, or saving properties to a file, or..?
Thanks in advance,
Re: What is Serializing good for?
there are some really good sites that clarifies this, mostly the Oracle API site for Java itself. It can be found here: Serializable (Java Platform SE 7 )
To understand when to use it, you have to understand what it is.
Serialization is a common term for taking an object and turning it into a series of bits, or an ordered stream of bytes. These can later on be read and deserialized into an identical clone of the object that was serialized. Just by thinking of this, I think you can come up with many good usages for this, such as storing information in a file to be sent to another system, or to send something over a network link.
In Java, you use the interface Serializable to make this happen. If you create a class that has to be able to be serialized, you just implement this interface. The good thing in Java, as far as I has understood is that this is done completely by the JVM and thus makes it possible to transfer the serialized object to any given system that has a JVM that can deserialize the object.
To use this, take a look at ObjectInputStream and ObjectOutputStream classes.
I hope this helps!