开发者_如何学PythonPossible Duplicate:
What is object serialization?
I know the details of how the JVM does the serialization of object graphs. What I am more interested in is the use of serialization? What was the necessity that drove the specification of serialization? More specifically, what practical uses does serialization have these days? Is is used as a means to store the data? Or is it used to send data across the network?
I will appreciate any links to this question if a full answer is not possible.
Thanks in advance.
Very simple. Suppose you have object graph and want to store it in file and then read it back. The luck of java programmer is that he/she does not have to implement gory details of field-by-field writing and reading the data. If whole graph is consists of serializable objects java does this work for you.
The same is relevant if 2 applications exchange the data.
Serialization is mainly used to send objects across the network. It's used in RMI, Spring's HttpInvoker, and other binary remote method invocation systems.
Using it for durable persistent storage is questionable, because it's impossible to query, binary and thus hard to analyze with a simple text editor, and hard to maintain when the classes change and their serialization format is thus modified. So a more open format is often chosen (XML, JSON, etc.)
Yes and yes! You can use it to send objects across the network, cache them, save them to disk, whatever you like. It is used for things like session replication between clustered JVM instances. Much of the time it is used under the covers by libraries that you use as well.
精彩评论