Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

JavaWorld Daily Brew

Markup Interface


Why Serializable interface is markup interface. What exactly do this interface and how. Can you create your own markup interface for serialzing purpose. How it will behave. I know markup interface does not have any method, exactly what is the use of markup interface. and jvm how to treat this type of markup interface.

Your rating: None Average: 3 (2 votes)

The purpose of the interface

The purpose of the interface is to signal that it's ok to serialize the state of the objects that implements the interface.

It does not make sense to serialize all fields in a class, like Object, various other classes in the SDK. (NOTE: serialization only applies to fields - not methods).

The JVM knows how to handle the serialization and it will serialize all the fields except static, final, native and transient ones.

If you need ways to control serialization process you should look into:

- private void writeObject(ObjectOutputStream out)
- private void readObject(ObjectInputStream in)

These methods, when implemented (requries no interface, has a special contract with the JVM.

You can create your own empty interfaces, but I have never personally done that!

It mean we implement

It mean we implement serializable interface of any class then we telling to JVM to treat differently then common class.

if i am wrong correct me.

Is JVM treated in differently of serializable interface implemented class? And yes then what type of action will take jvm?

I'm not sure I fully

I'm not sure I fully understand your last question.

A class that implements serializable is just a regular class after the implementation. When the JVM sees the serializable interface it knows it need to serialize every sub class also, when and if you execute code to serialize the state of the objects.

Note the point of having serializable interface is to stop the serialization process from going to far up the hierarchy of classes. As I stated earlier, it does not make sense to serialize Objects class and other JDK system classes.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <p> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <br /> <br> <strike>
  • Lines and paragraphs break automatically.
  • Use <!--pagebreak--> to create page breaks.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
Just checking to see if you're an actual person rather than a spammer. Sorry for the inconvenience.