Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

example answer to Developer's exam

 
Kathy Shkarlet
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I was browsing the sample questions / answers to the Developer's exam on Sun site and I'm not sure I agree with one of the answers.
In Question 3 (RMI vs sockets) one of the advantages they list is:
"RMI allows both state and behavior to be passed over the network".
But if I use serialization over socket connection - I'm sending an object over network. Object has both state and behaviour, so why are they listing it as the RMI advantage?!
Hope somebody enlighten me,
Thanks,
Kathy
 
Jerry Pulley
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kathy,
When you serialize an object yourself (via sockets), you're only passing the object's fields, not it's methods. You build a new object on the receiving end, using the fields passed over the socket connection. The class has to be on the client side as well as the server. The object's "behavior", from the point of view of the client, exists and runs on the client. Furthermore, all the connections to other objects that existed in the context of the server need to be recreated on the client side.
When you access an object via RMI, only the stub needs to be on the client side (it can, of course, be downloaded). The stub provides the interface to the object running on the server. The code implementing the object's behavior runs on the opposite (server) end of the connection, and the object continues to operate in its original context. The actual behavior is accessed remotely, which is not the case when you recreate the entire object on the client after serializing its state.
Jerry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic