• 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
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

doubt in serializatiion

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you want to have the state of object for a class, we go for serializtion concept. It means that we just implent serializable interface for our class.

Generally we don't implemment it in a class. Even if it is not implemented, the state of object(serialized)is serialized.


how it is possible?

How will take care of it?

How it is possible for java bean?


Can you please explan it...
 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
java.io.Serializable is a marker interface. A marker interface is an interface which do not declare any methods in it.

By implementing this class, we let the JVM know that this class needs to be treated differently and can be serialized.
 
arulraj michaelraj
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply.


If we don't implement serializable interface, what will it happen?
 
Marshal
Posts: 80093
413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If we don't implement serializable interface, what will it happen?

Easy question to answer: you can't serialize the object. Most people producing code for use in the "real world" would implement the Serializable interface on spec, because you can get a NonSerializableException if you try to serialize an instance whose fields are not all serializable.

There is another mechanism for (long-term) object persistence: use of JavaBeans. I hardly know anything about them
 
arulraj michaelraj
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Can we provide our own serialize concept by overriding method "writeObject(java.io.ObjectOutputStream)" in a class?

2. what about java-bean? sould we implement serializable interface for java bean to store the object of that bean?
 
Sunil Vasudevan
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1. Can we provide our own serialize concept by overriding method "writeObject(java.io.ObjectOutputStream)" in a class?



You can provide your own serialize concept. But on a practical assignment you would rarely need to do it.

2. what about java-bean? sould we implement serializable interface for java bean to store the object of that bean?



Java bean is a java class that adheres to Java Bean specification. http://java.sun.com/products/javabeans/docs/spec.html

Yes, java bean classes should also implement Serializable interface.
 
reply
    Bookmark Topic Watch Topic
  • New Topic