Storing an object info

Discussion in 'Java' started by Firewalker, Jul 15, 2004.

  1. Firewalker

    Firewalker Guest

    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
     
    Firewalker, Jul 15, 2004
    #1
    1. Advertising

  2. Firewalker

    Murray Guest

    "Firewalker" <> wrote in message
    news:BRoJc.61$...
    > 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.
     
    Murray, Jul 15, 2004
    #2
    1. Advertising

  3. Firewalker

    Firewalker Guest

    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$...
    > > 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.
    >
    >
     
    Firewalker, Jul 15, 2004
    #3
  4. Firewalker

    Murray Guest

    > 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 ...
     
    Murray, Jul 15, 2004
    #4
  5. Firewalker

    Liz Guest

    "Murray" <> wrote in message
    news:40f6918a$0$18195$...
    > > 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.
     
    Liz, Jul 16, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Paugh
    Replies:
    0
    Views:
    412
    Jon Paugh
    Jan 22, 2004
  2. abraxas
    Replies:
    0
    Views:
    337
    abraxas
    Aug 3, 2006
  3. Jeff
    Replies:
    5
    Views:
    839
    =?Utf-8?B?TWlsb3N6IFNrYWxlY2tpIFtNQ0FEXQ==?=
    Feb 11, 2007
  4. toton
    Replies:
    11
    Views:
    741
    toton
    Oct 13, 2006
  5. Jonathan Wood
    Replies:
    1
    Views:
    531
    Jonathan Wood
    Jun 2, 2008
Loading...

Share This Page