Save objects to disk or save Vector of objects ?

I suppose this question applies to many different situations, but in this case 'm building and Addressbook. I save all the adresses individually in little *.add files. When the program opens these files are then (ObjectInputStream) placed in a Vector which is placed in a JList.

Now this works fine, but would it be better and/or easier to save the Vector to the disk, or maybe even the JList? (if you can do that with a JList, i presume you can).

My thought is that in connection with sorting the list, it might be easier to save a Vector, since it then would be sorted beforehand next time you open it.

But is this the only difference between the two approaches?

[692 byte] By [Geckex1a] at [2007-9-19]
# 1
Saving the Vector sounds perfectly reasonable.Saving JList probably won't work, because I don't believe it is Serializeable. (In general, objects that do I/O are not serializeable.
bschauwea at 2007-7-8 > top of java,Core,Core APIs...
# 2
No, another difference is that when you change an address, you either have to save the single .add file that was affected or you have to save the entire Vector of addresses. And a similar difference occurs when you add or remove an address. And no doubt there are other differences.
DrClapa at 2007-7-8 > top of java,Core,Core APIs...
# 3
And if one add file becomes corrupted then you loose that single entry. With one file for the vector you loose everything.If you are just mucking around maybe you should consider venturing in the wonderful world of databases.
jschella at 2007-7-8 > top of java,Core,Core APIs...
# 4

yeah - serialization is carp :-/ (slow, inefficient, and awkward)

rob,

> And if one add file becomes corrupted then you loose

> that single entry. With one file for the vector you

> loose everything.

>

> If you are just mucking around maybe you should

> consider venturing in the wonderful world of

> databases.

Abusea at 2007-7-8 > top of java,Core,Core APIs...
# 5
ok, we'll maybe I'll go venturing (some day soon).For now I'll stick to my .add filesThanx for the feedback + dukes to "jschell" for the Database angle (someones gotta have 'em).
Geckex1a at 2007-7-8 > top of java,Core,Core APIs...
# 6

I did this a couple of times and my conclusion was that using serialization for keeping stuff like this is primarily a convenience issue. Creating a .add file with a serialized object doesn't take much thought and the I/O code is already written. In my experience though the cost of versionUID mismatches and the like make it much more reasonable to simply use DataInputStream and DataOutputStream so that you have maximum flexibility in the future.

Databases are nice but I would never use a mail client for example if it requred me to install Oracle. Maybe if you used PointBase or InstantDB you could get the niceties of a DB without having a separate app.

I would definitely not serialize an entire vector though, talk about trouble!

smithsa at 2007-7-8 > top of java,Core,Core APIs...
# 7

quote:

> In my experience though the cost of versionUID mismatches

> and the like make it much more reasonable to simply

> use DataInputStream and DataOutputStream so that you

> have maximum flexibility in the future.

why is this more flexible?

because you do not have to cast the Object to an Address Object?

Geckex1a at 2007-7-8 > top of java,Core,Core APIs...
# 8
i think the flexibility is at you may consider saving address in XML format and let any other program use this .add files rather than keep the data in Object format which can be used only through serialization
Joe13xa at 2007-7-8 > top of java,Core,Core APIs...
# 9
Hey,May I ask whether u can post the code for saving the entire vector object?
chesterhenga at 2007-7-8 > top of java,Core,Core APIs...