This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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: 18765
    
  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