• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

concerning serialization

 
Ranch Hand
Posts: 49
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 300
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.

 
krillian konstatos
Ranch Hand
Posts: 49
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What issues do you have reading from the serialized files?
 
krillian konstatos
Ranch Hand
Posts: 49
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 80653
476
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic