Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / June 2008

Tip: Looking for answers? Try searching our database.

Newbie - I don't understand interface Serializable

Thread view: 
zalek - 28 Jun 2008 17:23 GMT
The  interface Serializable does not have any methods or variables.
If I create a subclass of an Object class - is this class
Serializable?
For example, let say I define:

public class A extends Object{
int a;
}

Now make the following definition:

public class A extends Object implements Serializable{
int a;
}

What makes the 2nd definition Serializable?

Thanks,

Zalek
Lasse Reichstein Nielsen - 28 Jun 2008 17:32 GMT
> The  interface Serializable does not have any methods or variables.

Correct. It's a "marker interface" which merely marks the class as being
intended for serialization. The serialization code checks for the marker,
and refuses to serialize something without it - not because it couldn't,
but just because it won't - serializing and derserializing something not
build for it could cause unexpected trouble.

Today it would probably have been implemented as an inherited
annotation.

> If I create a subclass of an Object class - is this class
> Serializable?

If it implements the Serializable interface.

> For example, let say I define:
>
> public class A extends Object{
> int a;
> }

Yes, that class isn't serializable. No need to write the "extends Object".
The class will automatically extend Object if no other superclass is
given.

> Now make the following definition:
>
[quoted text clipped - 3 lines]
>
> What makes the 2nd definition Serializable?

That it implements the interface! That means that the default
serialization code will accept to serialize and deserialize objects
of that class.

/L
Signature

Lasse Reichstein Nielsen
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
 'Faith without judgement merely degrades the spirit divine.'

Mark Space - 28 Jun 2008 19:01 GMT
> The  interface Serializable does not have any methods or variables.
> If I create a subclass of an Object class - is this class
> Serializable?

Lasse gave you some really good answers to your questions.  Here's a
decent how-to on serialization from Sun.  It explains further how
serialization actually works and gives some guidelines how to use it.

<http://java.sun.com/developer/technicalArticles/Programming/serialization/>
Mike Schilling - 29 Jun 2008 04:16 GMT
>> The  interface Serializable does not have any methods or variables.
>> If I create a subclass of an Object class - is this class
[quoted text clipped - 6 lines]
>
> <http://java.sun.com/developer/technicalArticles/Programming/serialization/>

And her is everything you'd ever want to know about serialization:
http://java.sun.com/j2se/1.3/docs/guide/serialization/spec/serialTOC.doc.html
Arne Vajhøj - 29 Jun 2008 04:38 GMT
>>> The  interface Serializable does not have any methods or variables.
>>> If I create a subclass of an Object class - is this class
[quoted text clipped - 9 lines]
> And her is everything you'd ever want to know about serialization:
> http://java.sun.com/j2se/1.3/docs/guide/serialization/spec/serialTOC.doc.html

I don't think it has changed, but:

http://java.sun.com/javase/6/docs/platform/serialization/spec/serialTOC.html

Arne
Roedy Green - 29 Jun 2008 02:29 GMT
On Sat, 28 Jun 2008 09:23:07 -0700 (PDT), zalek
<zalekbloom@hotmail.com> wrote, quoted or indirectly quoted someone
who said :

>The  interface Serializable does not have any methods or variables.
>If I create a subclass of an Object class - is this class
>Serializable?
>For example, let say I define:

it is just marker to indicate you have thought through the class to do
the transients etc. needed to make it serialisable.
Signature


Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.