File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Serialization marker Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Serialization marker Interface" Watch "Serialization marker Interface" New topic

Serialization marker Interface

Grssridhar Ramakrishnan

Joined: Jul 05, 2013
Posts: 1
Hi there !! Im preparing for OCJP . In Which I came up with a doubt !!! According to the book , Serialization has no methods to implement !! I got a doubt here . The interface is not even implementing the method then what is the use of using the serializable Interface . I m thinking then for what purpose we are implementing the specially serializable interface.. Anyone give me the explaination about the marked interface and normal interface ?this quest may be silly but i dont think so rather i can ask here to get clear in JAVA
sahil kumar garg sangrur

Joined: Jun 05, 2012
Posts: 19
this is a marker interface in java to check that if the particular class is implementing this interface only then allowed to write the object of particular class in stream..otherwise not allowed
Ashok Donepudi

Joined: Jul 05, 2013
Posts: 2
Hi Ramakrishnan,

When a class implements serializable it informs the JVM that this class needs to be serializied. when a class is marked serializable it generate a serialUID for this class and compares when you desirialize the object.

public class Test implements Serializable{

public static void main(String args[]){
System.out.println("helllot ");


Now your Test class is serialized unless you create instance of this class and send across the network or save an object there is no point in using the serializtion.

Winston Gutkowski

Joined: Mar 17, 2011
Posts: 8945

Grssridhar Ramakrishnan wrote:Anyone give me the explaination about the marked interface and normal interface ?

As already stated, a marker interface is simply an interface with no methods.

Their value is an oft-debated subject, since it would seem to go against the grain of Object-Orientation; but I'd say that they have two possible advantages:
  • 1. They serve the purpose of a boolean field without the added space.
  • 2. They allow you to document an aspect of behaviour which might not otherwise be obvious. A good example of this is the RandomAccess marker interface.

  • All I can tell you is: they're rare. And one of the most fiercely debated ones (java.lang.Cloneable) should probably never have been a marker interface to begin with.

    this quest may be silly but i dont think so...

    There are no silly questions. I can't vouch for the answers though.


    Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
    Articles by Winston can be found here
    Vignesh Gopal

    Joined: Jun 29, 2013
    Posts: 16
    It can also be called as Tagged Interface, Dummy Interface, Empty Interface.

    We are implementing this Interface just for tagging purpose.

    Serializability of a class is enabled by the class implementing the interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable.

    When traversing a graph, an object may be encountered that does not support the Serializable interface. In this case the NotSerializableException will be thrown and will identify the class of the non-serializable object.

    We are using this interface to backup the current state of object and reusing it later through deserialization. If we want to send a value to one place to another usually we will save the data in DB and then transfer it. Instead we are send the data through network as a Object and in another end we will deserialize it.

    Another realtime example for this is, When we saving a particular game in PC a file will be saved. That file will save the current instances of the object. Later it will deserialize when you continue your game by loading that file.

    Look at following image. After serializing ‘SerializationBox’ in the above sample code, I opened the output in a hex editor. You can use Notepad++ and hex plugin to open the serialized file.

    Let us look at contents byte by byte and find out what they are. It starts with “ac ed”. It is is called STREAM_MAGIC. It is a magic number (java API guys says) that is written to the stream header. It denotes that is start of serialzed content.

    Similarly every character has a meaning. Actually the serialized file is more bulkier than you would expect, as it has a huge header the meta information of the classes involved and finally the content. Object Serialization Stream Protocol have a look at chapter 6.4.2 Terminal Symbols and Constants. It gives you list of symbols and constants used in serialization.

    Decrypting Serialized Java Object

    In the image, I have underline a unit of information in a separate color for you to easily identify.

    ac ed – STREAM_MAGIC – denotes start of serialzed content
    00 05 – STREAM_VERSION – serialization version
    73 – TC_OBJECT – new Object
    72 – TC_CLASSDESC – new Class Descriptor
    00 26 – length of the class name
    63 6f 6d 2e 6a 61 76 61 70 61 70 65 72 73 2e 73 61 6d 70 6c 65 2e 53 65 72 69 61 6c 69 7a 61 74 69 6f 6e 42 6f 78 – class name
    57 fc 83 ca 02 85 f0 18 – SerialVersionUID
    02 – this object is serializable
    00 01 – count of properties in the serialzed class – one property in our example
    42 00 10 – private byte
    73 65 72 69 61 6c 69 7a 61 62 6c 65 50 72 6f 70 78 70 – property name – serializableProp in our example
    0a – 10 the value – This is the persisted value of the property in our sample

    For Better Understanding just go through this Serialization Java Docs
    Pankaja Shinde
    Ranch Hand

    Joined: Sep 15, 2006
    Posts: 87
    Interfaces with empty bodies are often used as markers to tag classes as having a certain property or behavior. Such interfaces are also called ability interfaces. Java APIs provide several examples of such marker interfaces: java.lang.Cloneable,, java.util.EventListener.
    I agree. Here's the link:
    subject: Serialization marker Interface
    It's not a secret anymore!