• Post Reply Bookmark Topic Watch Topic
  • New Topic

why serialization  RSS feed

 
satish varma
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai to all Ranchers,

"Serialization is writing the state of java object into a file system" but i have one doubt that is why we have to use file system to store object state by using Serialization why not in database( means SQL Db or some other)

Thank you
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please QuoteYourSources. Who said you have to use the file system? You get a byte stream and can do with that whatever you want.

But as you get only a byte stream that doesn't make sense to anyone else than a Java VM, storing this in a SQL db typically is not very useful. Sure, you can store it in a blob field, but you loose all the structured approaches that SQL is providing.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think one point needs to made clearer: serialization in Java can take different forms. The binary approach (using Object[In|Out]putStream) hands you a byte[] array that is usable only by JVMs, as Hauke said. What's more, this approach is not guaranteed to work across JVM versions - good luck getting an object serialized with Java 6 b10 to work with a Java 6 b20 JVM, much less between Java 5 and Java 6 JVMs.

But other approaches exists; for example, if an object conforms to JavaBean standards, then the java.beans.XMLEncoder/XMLDecoder classes create an XML representation that is guaranteed to work across JVM versions, is amenable to XML processing, and is searchable when stored in a file system or DB.
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Back in Java 1.0, when the most popular usage of the language was for applets, serialization was mostly about transferring the data in an object instance between the browser and the server. And we were writing our own, there was no support for this provided in the language. But I think it's clear whoever said "file system" just wasn't thinking broadly enough.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!