• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Where Serialized Objects will be stored?

 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This is my sample code,



All it will do is simply serialized and de-serialized. But, The serialized object, where will be stored? If it is jvm, then how can I store data permanently in serialized mode. Like for example, consider a simple game. Game have a feature like you can save the current level and you can shut down the game. When you open the same again(after so many days), it'll start from the level where you saved last time not from the beginning level. How can you achieve this. In that type of case, should we save that data into DB instead of doing serialize? I mean, serialization is volatile, like until and unless program shutdown serialization works after that it'll not right?(I think yes, exactly don't know)

Thanks:
Ramakrishna K.C
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The serialized objects are stored in the file "nameStore", like the code specifies. Where that file is created depends on what the default directory is when this code is run. If you want control over the directory, use absolute paths instead of relative paths.

serialization is volatile, like until and unless program shutdown serialization works after that it'll not right?


I'm not sure what you're trying to say here, but serialization is frequently used to store data for later use during a future invocation of the JVM. So I think your understanding is wrong.

Personally, I don't like to use binary serialization, I prefer XML serialization using the java.beans.XMLEncoder and XMLDecoder classes. For storing game status it should be easy to meet the requirement that the serialized classes obey JavaBeans conventions.

You should also check out the java.util.prefs package. For a desktop app that may be a better fit than serialization - for example, you don't have to worry about files, and where they might get stored.
 
Master Rancher
Posts: 5122
82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The serialized object is stored wherever your code specifies it should be stored. In this case, that's controlled by the part that says

new FileOutputStream("nameStore")

That causes the code to create a new file (possibly overwriting an existing file) named "nameStore", in the current directory (the directory you're running from). Later code causes the program to read from that same file, to deserialize the object. You can read up on FileOutputStream, and input and output streams in general, to understand better how this works. A good place to start is the Java Tutorial on Basic I/O.
 
Mike Simmons
Master Rancher
Posts: 5122
82
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Curses - I've been Ulfed! ;)
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic