• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Methods of Marker Interfaces

 
Ranch Hand
Posts: 244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43009
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43009
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 43009
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't the whole serialization process implemented in the ObjectOutputStream class (and classes used by it)?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!