aspose file tools
The moose likes Java in General and the fly likes Methods of Marker Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Methods of Marker Interfaces" Watch "Methods of Marker Interfaces" New topic
Author

Methods of Marker Interfaces

Kousik Majumder
Ranch Hand

Joined: Sep 30, 2007
Posts: 219
Hi all,

Can anybody tell me where the methods of marker interfaces are written?
As because the marker interfaces contain no method.
i.e : For Cloneable() interfaces where the clone() method is written?


Thanks,

Kousik


Thanks in Advance,
Kousik
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35256
    
    7
Since marker interfaces do not contain methods, there's no implementation to point to. See this FAQ entry for some more information on marker interfaces.

clone is defined in the Object class, but it is not part of the Cloneable interface. Cloneable merely governs whether clone may or may not be called. (That of course begs the question: why wasn't clone made part of Cloneable, and that interface implemented by all cloneable classes, instead of adding the method to the Object class?)
[ January 10, 2008: Message edited by: Ulf Dittmer ]

Android appsImageJ pluginsJava web charts
Parmeet Singh
Greenhorn

Joined: Feb 09, 2006
Posts: 22
Implmentation for marker iterfaces is provided by the JVM as in most of the cased implementation is native.

By implementing java.io.Serializable interface, we just instruct the jvm that this particular object can be serialized and trasfered over net.

Read java vm spec for more clarrification.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35256
    
    7
Originally posted by Parmeet Singh:
Implmentation for marker iterfaces is provided by the JVM as in most of the cased implementation is native.


No. The implementation of marker interfaces can be provided by the JVM, and it can be native, but generally it will be implemented by Java code in a user class or a class in the Java Class Libraries. Remember that implementing Serializable is about deciding which classes may be serialized, not about actually serializing them. See here for some other such interfaces.
Parmeet Singh
Greenhorn

Joined: Feb 09, 2006
Posts: 22
Remember that implementing Serializable is about deciding which classes may be serialized, not about actually serializing them.

I Agree with this. totally.

but who actually serialized it, where actually it get it serialized. isnt it in JVM. JVM knows which object to serialized by checking if that object implements Serializable interface.

Please assist if am wrong.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35256
    
    7
but who actually serialized it, where actually it get it serialized. isnt it in JVM.

Yes, serialization is implemented in the JVM. But you were talking about marker interfaces in general being implemented in the JVM, and that is not true.
JVM knows which object to serialized by checking if that object implements Serializable interface.

The check for whether to serialize a class is not done in the JVM, it is part of the java.io.ObjectOutputStream class. If you search its source code for "instanceof Serializable" you'll find that check, and the code that throws an exception if the object to be serialized doesn't implement Serializable.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Isn't the whole serialization process implemented in the ObjectOutputStream class (and classes used by it)?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18670
The source code for ObjectOutputStream shows that, as of JDK 6, there are a couple of native methods, but the vast majority of serialization is accomplished by regular Java code inside ObjectOutputStream and inside ObjectStreamClass (which also has just a couple native methods). Of course ObjectStreamClass uses a lot of reflection, and those reflective methods are often native, so there's no single clear answer to this. I'd say most of serialization is implemented in Java code, and some isn't.

Also note that Externalizable is a subinterface of Serializable that does contain methods, allowing people to write their own serialization code in Java classes. So serialization may be accomplished that way as well, and if you do that, you are both deciding that the class may be serialized, and also deciding how to serialize it.

But more generally, whatever is done with marker interfaces, the code that uses them may be regular Java code, or native code. I think regular Java code is much more common, but does it really matter in general? Both are possible, and people using the code really don't need to know or care in most cases. The fact that Serializable is implemented a certain way tell s us nothing about Cloneable or other marker interfaces.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Methods of Marker Interfaces
 
Similar Threads
What exactly is a Marker Interface?
Marker interfaces
marker interfaces
small doubt regarding Marker Interface
Cloneable and Clone...