It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Partner Sites
Board index Programming Java Forum

serializable and cloneable

serializable and cloneable

Postby karthikbaskar on Thu May 03, 2007 2:26 pm

can anyone explain about where to use serializable and cloneable. For what purpose a class should extend the above two.
karthikbaskar
 
Posts: 4
Joined: Tue May 01, 2007 6:54 pm

Postby skoiloth on Wed May 09, 2007 12:16 pm

the Serializable and Cloneable are marker interfaces. All of these marker interfaces do not define methods; instead, they identify a class as having a particular capability.

In the case of Serializable, the interface specifies that if the class is serialized using the serialization I/O classes, then a NotSerializableException will not be thrown (unless the object contains some other class that cannot be serialized). Cloneable similarly indicates that the use of the Object.clone() method for a Cloneable class will not throw a CloneNotSupportedException.

Serializable is just a "marker interface." It doesn't declare any methods. It's just a flag that other methods can check. DataOutputStream.writeObject checks whether the class implements Serializable, and throws and excpetion if it doesn't.
:)
skoiloth
 
Posts: 6
Joined: Wed May 09, 2007 10:51 am


Return to Java Forum

Who is online

Users browsing this forum: No registered users and 1 guest

cron