Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Storing an object info

Reply
Thread Tools

Storing an object info

 
 
Firewalker
Guest
Posts: n/a
 
      07-15-2004
Hello guys,
I am trying to create a linked list where its nodes are StringBuffer
object. The thing that I wan to store this linked list somehow so that when
I reopen the java progra, it can loads the linked list again.
I had a method in my mind which is to store an object in the file and read
it back again.
The thing that I dont know how to do it, Can anyone point me to the righ
direction?
Or if you have a different effective method, would you please give me some
help?
Thanks alot for your help



 
Reply With Quote
 
 
 
 
Murray
Guest
Posts: n/a
 
      07-15-2004

"Firewalker" <> wrote in message
news:BRoJc.61$ rs.com...
> Hello guys,
> I am trying to create a linked list where its nodes are StringBuffer
> object. The thing that I wan to store this linked list somehow so that

when
> I reopen the java progra, it can loads the linked list again.
> I had a method in my mind which is to store an object in the file and read
> it back again.
> The thing that I dont know how to do it, Can anyone point me to the righ
> direction?
> Or if you have a different effective method, would you please give me

some
> help?
> Thanks alot for your help


If performance isn't critical, you could Serialize the object and write it
to a file using ObjectOutputStream. There are many serialization tutorials
out there, try here for starters (random Google result):
http://www.acm.org/crossroads/xrds4-2/serial.html

I mention performance because often serialization of objects isn't terribly
efficient compared to more specific saving strategies. There's overhead of
saving information about the class that is neede to regenerate the object.
There are also some gotchas, e.g. different versions of class files. But in
most cases performance isn't a problem and it's the easiest solution.


 
Reply With Quote
 
 
 
 
Firewalker
Guest
Posts: n/a
 
      07-15-2004
Thank you for your reply, but isn't StringBuffer and LinkedList already
serialized objects??!
Also, performance is not an issue here.Btw, does this work in survletes?
This is the main reason for saving the object because after shutting tomcat,
I want the information to be kept when I restart tomcat again.

Thanks again for your help

"Murray" <> wrote in message
news:vspJc.1816$...
>
> "Firewalker" <> wrote in message
> news:BRoJc.61$ rs.com...
> > Hello guys,
> > I am trying to create a linked list where its nodes are StringBuffer
> > object. The thing that I wan to store this linked list somehow so that

> when
> > I reopen the java progra, it can loads the linked list again.
> > I had a method in my mind which is to store an object in the file and

read
> > it back again.
> > The thing that I dont know how to do it, Can anyone point me to the

righ
> > direction?
> > Or if you have a different effective method, would you please give me

> some
> > help?
> > Thanks alot for your help

>
> If performance isn't critical, you could Serialize the object and write it
> to a file using ObjectOutputStream. There are many serialization tutorials
> out there, try here for starters (random Google result):
> http://www.acm.org/crossroads/xrds4-2/serial.html
>
> I mention performance because often serialization of objects isn't

terribly
> efficient compared to more specific saving strategies. There's overhead of
> saving information about the class that is neede to regenerate the object.
> There are also some gotchas, e.g. different versions of class files. But

in
> most cases performance isn't a problem and it's the easiest solution.
>
>



 
Reply With Quote
 
Murray
Guest
Posts: n/a
 
      07-15-2004
> Thank you for your reply, but isn't StringBuffer and LinkedList already
> serialized objects??!


No, they are Serializable <-- note the "able" on the end. This means you
are able to serialize them to a file/other storage medium if you want to. If
you read the link in my other post, you'll see how to write serializable
objects to a file.

> Btw, does this work in survletes?
> This is the main reason for saving the object because after shutting

tomcat,
> I want the information to be kept when I restart tomcat again.


Well it has nothing to do with servlets, it's just plain old Java code which
will work no matter what kind of program you're dealing with. Can you post
some code so we can see exactly what you're trying to do? There may well be
a better solution ...


 
Reply With Quote
 
Liz
Guest
Posts: n/a
 
      07-16-2004

"Murray" <> wrote in message
news:40f6918a$0$18195$ u...
> > Thank you for your reply, but isn't StringBuffer and LinkedList already
> > serialized objects??!

>
> No, they are Serializable <-- note the "able" on the end. This means you
> are able to serialize them to a file/other storage medium if you want to.

If
> you read the link in my other post, you'll see how to write serializable
> objects to a file.
>
> > Btw, does this work in survletes?
> > This is the main reason for saving the object because after shutting

> tomcat,
> > I want the information to be kept when I restart tomcat again.

>
> Well it has nothing to do with servlets, it's just plain old Java code

which
> will work no matter what kind of program you're dealing with. Can you post
> some code so we can see exactly what you're trying to do? There may well

be
> a better solution ...
>

Nothing says it has to be stored on disk in any particular way. Why
not just use a database table and put the info for each node into a tuple.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
User Images: Storing in Files VS Storing in Database Jonathan Wood ASP .Net 1 06-02-2008 05:56 PM
storing pointer vs storing object toton C++ 11 10-13-2006 11:08 AM
WebService returns object - storing that object in ViewState Mark ASP .Net 3 07-18-2006 02:12 PM
Object creation - Do we really need to create a parent for a derieved object - can't the base object just point to an already created base object jon wayne C++ 9 09-22-2005 02:06 AM
Thread.CurrentPrincipal vs storing user info in session Jon Paugh ASP .Net 0 01-22-2004 06:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57