This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

java.io.Serializable;

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could anybody explain what this does and why its needed to me??
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is it necessary for validation?
 
Dan Pollitt
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by "Validation"?
 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
You don't know me, but I've been looking all over the world for. Thanks to the help from this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic