Serialization is the process of converting a set of object instances that contain references to each other into a linear stream of bytes, which can then be sent through a socket, stored to a file, or simply manipulated as a stream of data. Serialization is the mechanism used by RMI to pass objects between JVMs, either as arguments in a method invocation from a client to a server or as return values from a method invocation. In the first section of this book, I referred to this process several times but delayed a detailed discussion until now. In this chapter, we drill down on the serialization mechanism; by the end of it, you will understand exactly how serialization works and how to use it efficiently within your applications.
Envision the banking application while a client is executing a withdrawal. The part of the application we’re looking at has the runtime structure shown in Figure 10-1.
Figure 10-1. Runtime structure when making a withdrawal
it mean for the client to pass an instance of
Money to the
server? At a minimum, it means that the server is
able to call public methods on the instance of
Money. One way
to do this would be to implicitly make
Money into a server as
well. For example, imagine that the client
sends the following two pieces of information
whenever it passes an instance as an argument: