Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

implementing serializeble interface in bean

 
Gevarghese
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it mandatory to implement sirializable or Externalizable interface for creation of bean ? please explain to me how can you relate bean with these interfaces
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it's not mandatory. If you're learning servlets/jsp now, you won't need to implement the interface.
You will have to when you're bean is put in a session in a distrubuted environment, if you want it to be migrated properly.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you plan on storing these beans in session, it's a good idea to make them serializable. Some containers (Tomcat, that I know of) will serialize all sessions to disk when the app or container is shut down for a re-start.
It then reads them back when it starts up.

If any object bound to session, directly or indirectly, doesn't implement serializable, this whole operation fails.

Also, as Ulf mentioned, in a clustered environment, Tomcat uses serialization for session replication.

I'm sure most containers have similar functionality.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"gevarghese kv",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Stefan Evans
Bartender
Posts: 1784
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it not one of the primary requirements of being a bean that it is Serializable?

The serializable interface is more of a marker than anything else. It just says "this class can be serialized". Most of the time the default implementation is just fine - so just make your bean "implement java.io.Serializable" and you're pretty much done.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic