File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Where Serialized Objects will be stored? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Where Serialized Objects will be stored?" Watch "Where Serialized Objects will be stored?" New topic
Author

Where Serialized Objects will be stored?

Ramakrishna Udupa
Ranch Hand

Joined: Aug 09, 2013
Posts: 253
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
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42951
    
  72
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.
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
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
Ranch Hand

Joined: Mar 05, 2008
Posts: 3018
    
  10
Curses - I've been Ulfed! ;)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Where Serialized Objects will be stored?