This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes java.io.Serializable; Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "java.io.Serializable;" Watch "java.io.Serializable;" New topic
Author

java.io.Serializable;

Nicola Guy
Ranch Hand

Joined: Jun 23, 2004
Posts: 91
Could anybody explain what this does and why its needed to me??
Dan Pollitt
Greenhorn

Joined: Jun 30, 2004
Posts: 9
Serializing an object means writing it to disk or a byte stream so that it can be persisted or sent to another JVM. At a later time the object can be read in an used.

Implementing the java.io.Serializable interface but adding no additional methods means you are stating that the object can be serialized by Java's default mechanism.

You should have a look at http://java.sun.com/docs/books/tutorial/essential/io/index.html
Nicola Guy
Ranch Hand

Joined: Jun 23, 2004
Posts: 91
is it necessary for validation?
Dan Pollitt
Greenhorn

Joined: Jun 30, 2004
Posts: 9
What do you mean by "Validation"?
Vijayendra V Rao
Ranch Hand

Joined: Jul 04, 2004
Posts: 195
Originally posted by Dan Pollitt:

Implementing the java.io.Serializable interface but adding no additional methods means you are stating that the object can be serialized by Java's default mechanism.



Precisely. First, you should be aware that one of the ways Interfaces could be defined is "Conformance to requirements". This means, the Java language says that "if your class conforms to some particular requirements, then it will be allowed to, or be able to carry out specific operations". This is the most general way of describing an interface.

As Dan Pollitt has rightly pointed out, by implementing the Serializable interface, you are declaring that your class' objects are going to be able to be saved to a file. The Serializable interface is a tagging interface. So, if you wish to persist your objects then you will have to implement the Serializable interface.


Vijayendra <br /> <br />"The harder you train in peace, the lesser you bleed in war"
Weij Yin
Greenhorn

Joined: Aug 02, 2004
Posts: 9
is it necessary for validation?


java.io.Serializable is an interface that is entirely empty. A class can implement this interface simply by naming it in its implement clause without having to implement any methods. This technology is a useful way to provide additional imformation about an object, and it does not affect the normal operation on an object.

java.lang.Cloneable is another such interface. It defines no method, but identifies the class as one that allows its internal state to be cloned by the clone()method of the Object class. For example:


Object o;
Object copy;
if(o instanceof Cloneable) copy = o.clone();
else copy = null;


Now, let's come back to java.io.Serializable interface. A class should implement this interface simply to indicate that it allows itself to be serialized and deserialized with ObjectOutputStream.writeObject() and ObjectInputStream.readObject(). In other words, the class should be converted into a stream of bytes that can later be deserialized back into a copy of the original object. When to use it? in the area of network programming and distributed programming, because they have issues such as delivery delay, difference of systems, and network failing.

Regards,
Weij


AspectJ, an asepct-oriented extension to Java programming language.<br /><a href="http://www.aspectj.org" target="_blank" rel="nofollow">http://www.aspectj.org</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.io.Serializable;