aspose file tools*
The moose likes Java in General and the fly likes concerning serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "concerning serialization" Watch "concerning serialization" New topic
Author

concerning serialization

krillian konstatos
Ranch Hand

Joined: Jan 03, 2011
Posts: 49

hi, all!

i have a question about the serialization framework in java. is it a good or bad procedure to use the classes found there to store
user input like you would in a database or xml file? i haven't try this before but i am curious about it but i have also not yet found
any really good articles on the web that covers the issue of using serialization as a database. it would be gladly welcome to see if someone
could post some links to articles on this here. i know how to use java.sql classes and xml classes as a database but not serialization.
is it better to store user data in a plain textfile than using serialization for this purpose? i have heard different opinions about this
question but i haven't explored this any further.

thank you very much in advance,
regards, krillian!
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1687
    
  12

This totally depends on the implementation of the project.

Some projects may require the use of databases, others may require a simple file. One of the projects I made for school required the use of both serialization and SQL in order to meet the requirements of the project. Smaller projects would probably be considered wasteful if you needed to install a whole database..... think of a simple game and keeping track of scores or players or whatnot. It also depends on if there needs to be concurrent access by more than one user.... use of a file might cause data corruption.


When you do things right, people won't be sure you've done anything at all.
Javin Paul
Ranch Hand

Joined: Oct 15, 2010
Posts: 281


See both approaches has there advantage and disadvantages.

1. if you use serialization for storing data , you can only open that file with java , while if you use text file you can open in an editor , which comes very handy inccase of any issue or debugging.

2. storing data in database is ideal if you use data to generate various reports and only database can provide you sophisticated query mechanism , also storing data in database itself handle multiple issues e..g storage, backup , data type validation etc.

I don't think Serialization is meant for storing large data and can provide benefit over database.


http://javarevisited.blogspot.com - java classpath - Java67 - java hashmap - java logging tips java interview questions Java Enum Tutorial
krillian konstatos
Ranch Hand

Joined: Jan 03, 2011
Posts: 49

hello, ranch!

thank you very much for your kind reply, Javin and i really like your website it covers a lot of ground for me. i guess it is better to use serialization when it comes to storing objects in some xml file maybe if you're writing some ide or something like that. but to use it as a database seem too complicated. i have tried to serialize objects as output but i have given up when it comes to read from serialized objects stored in a file. it almost seems impossible to make it work for me. i mainly use xml to store my user input and xpath to do queries. but again thank you so much for the reply and the posted link.

regards,
krillian!
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1687
    
  12

What issues do you have reading from the serialized files?
krillian konstatos
Ranch Hand

Joined: Jan 03, 2011
Posts: 49

hi!

i have tried the classes in the serialization library to store simple input in textfields in a textfile but i didn't knew how to extract this input as strings. but i used the ObjectInputStream class and tts method to accomplish this. but those strings contained characters that i couldn't filter out. i remember i tried to replace theese with regex methods in the String class like replaceAll(String regex, String replacement) + replace(char oldChar, char newChar) and split(String regex, int limit) but it didn't worked.

i want to use serialization because i think it would be good to store small input in textcomponents such as contact information. but right now i intend to stick with xml i am just curious .

regards, krillian.
Janeice DelVecchio
Saloon Keeper

Joined: Sep 14, 2009
Posts: 1687
    
  12

I'm really no expert at serialization, but the few times I did it, it was "plug and play"

Tips:
1. When you serialize, you need to know what kinds of objects (and many times how many of each) are going into the file
2. Same when you take them out of the file.

Other than that, you just use ObjectOutputStream and ObjectInputStream to do the job. There should be no need to worry about filtering characters. The whole object gets bundled up and packaged away for later use.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39409
    
  28
Find Thinking in Java™ by Bruce Eckel; there is a lot about serialisation in that book.
I don't think this is a "beginning" discussion any more, so I shall move it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: concerning serialization