java.io.Serializable

Centinall

Member
Jul 5, 2003
59
0
0
if someone could explain to me what exactly Serializable does, i would appreciate it...

public class UserView implements java.io.Serializable {

i imagine it has something to do with scaling your application... UserView is a presentation JavaBean with the usual get/set methods... basically UserView is a DTO to transfer data from one layer of my application to another, implementing the MVC model 2 approach to web application programming.

thanks in advance for your help...

btw, what do you guys think of using Hibernate as an ORM? i seem to hear nothing but good things about it...
 

Daishiki

Golden Member
Nov 9, 2001
1,943
36
91
well... in the programs i've used serialization was for database files. the data, whether in the forms of arrays or vectors or whathaveyou, could be serialized and writen into a file as an Object. you could then read the object back in, then cast it back to the right type. just a way to store data without having to worry about how to read it from a file. not sure if that explanation helps.
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
I've used it in two different places - the first is to write to a file (like mentioned above), and when sending objects over socket connections. Either way you're sending the object over a stream. The serializable interface lets the stream know that the class can be deconstructed into a byte stream, and reconstructed at the other end.

For simple classes, you don't need to to do anything but "implements Serializable". Others, though, you have to specify which variables to keep and which you shouldn't serialize along with the object (keyword transient ). And if that's not enough, there are two methods you can implement, read/write (note sure of the names, they're in the java api) so you can explicitly specify how to break the object down into a series of bytes, and how to reconstruct it.