File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Implementing Serializable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Implementing Serializable" Watch "Implementing Serializable" New topic
Author

Implementing Serializable

Yed Su
Greenhorn

Joined: Mar 02, 2011
Posts: 10

Is it mandatory to implement Serializable interface if an object is to be serialized ? I worked with ObectInput/ObjectOutput and FileInput/FileOutput without implementing Serializable interface for my class and it worked perfect. Just curious to understand the Serializable.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

Yes, to be serialized, a class must be marked Serializable. If you observed otherwise, I suspect either (1) you weren't actually using serialization, or (2) your classes inherited Serializable from a parent class.


[Jess in Action][AskingGoodQuestions]
Yed Su
Greenhorn

Joined: Mar 02, 2011
Posts: 10

Thanks Ernest,

But I dont have any super class and Im using serialization as well. Please check the following example:

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18509
    
  40


Hashtable instances, along with String, Integer, and Double instances are all Serializable -- try putting something that is not serializable into that hashtable.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hashtable, String, Integer, and Double all implement Serializable, so all the objects you're writing are, indeed, serializable.
Yed Su
Greenhorn

Joined: Mar 02, 2011
Posts: 10

Ernest and Henry Thanks for making me realize Serialize.. !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Implementing Serializable
 
Similar Threads
Serialization
Entity implements serializable
what is the output
should an interface implement Serializable
Re: Serializable