Yes you are right, u definitely need the class file representing the Object u w'd want to read (on the other side of the network),
but then in RMI they also send in the required class files when required, they (i mean SUN ) know that it's a JVM on the other side of the network as well so they dynamically send the class files too...amazing is'nt it. The client does'nt need to worry about knowing the class files..server will take care of supplying it in runtime through the network!
Again am just a entry-level (1 year) guy in Java, so i'm in no position to comment on other distributed technologies..
okay as for an example.
write a ServerSocket waiting for connections on a port.
You can write a Socket client which w'd connect to that port. Now instead of specifying the FileOutputStream in the
ObjectOutputStream constructor specify,..
the code w'd look something like this..
class MyFrame extends JFrame implements Serializable{
////put some GUI stuff here.
}
//Client
try{
MyFrame f = new MyFrame();
Socket s = new Socket(5000);
ObjectOutputStream os = new ObjectOutputStream(s.getOutputStream());
os.writeObject(f);
os.flush();
}
//
on server...
try{
ServerSocket ss = new ServerSocket(5000); //same machine
Socket s = ss.accept();
ObjectInputStream i = new ObjectInputStream(s.getInputStream());
MyFrame m = (MyFrame)i.readObject();
}
....
Remember the constructor for the Object u just read in w'd never get called. In the sense, u don't construct a new object, you just read in something which has been sent to you.
But Serilaization provides ways to get around this.
i want you to check that out from a tutorial / a book
Now you don't need to "write" a JFrame into a file and then send the file across.
As i mentioned earlier, serializing a widget is probably a foolish idea but then u can get something like that done
..what am actually trying to point out is that you can write in such "huge" objects with just a writeObject().
Now can you imagine writing a JFrame to a file using RandomAccessFile alone and then sending it to someone.
One of the numerous advantage again is that ObjectOutputStream takes the onus of going through your object "recursively", then store it in some fashion, while we developer's have fun.
karthik.