java interface constructor
There are two aspects of java interfaces that are commonly misunderstood, those that are seen as a part of the language, and those that are seen as the actual implementation.
The first is that the actual implementation, which is what is used to create an instance of the class, is Java’s implementation. It does the actual work of creating the instance. But the interface is seen as something that may be added to later, allowing us to declare a class in the future and not have to rewrite the whole class to use the new interface.
There are two other common misconceptions about interfaces. First, they can be used as syntax sugar, and second, they can be used to “hide” implementation details, making them easy to change without breaking existing code. There is a third misconception that’s kind of the same, but doesn’t have a catchy name: the idea that an interface could be used to hide implementation details. An interface is often used to declare a behavior that is not tied to a specific implementation.
The idea of an interface is that it can be used to hide implementation details. And that’s what java.io.Serializable is. It allows you to declare that a class can act as a serializable object. By declaring it, you can avoid making your classes serializable if you don’t want to (in the Java convention, the serialization is done by the compiler, and the serialization is done by the runtime).
I know what you’re thinking, what does this have to do with java.io.Serializable? It’s a standard java.io.Serializable, but what does that have to do with java.io.Serializable? The Java Serialization format is a well-established format, and has been around since the 1990s. The format is designed so that you don’t have to write code to serialize and deserialize objects.
The problem is, as a language, it forces you to write code for every object that you want to serialize. If its not in the standard java.io.Serializable, you can write a simple object class with a constructor, and then you have to make the constructor “public”. If your object has no public constructor, then the compiler will throw an error for you. Which means that the serialization format may not be supported by the runtime. Unless you use the java.io.
The standard java.io.Serializable interface is not supported by all implementations of Java. When Java7 comes out, it will change this situation. We will support the Serializable interface in Java7, but not the Serializable format.
So, if you use the standard java.io.Serializable interface, the serialization format will not be supported. But if you use the serializable interface, then you can make your own objects that are actually Serializable and you won’t have to worry about the compiler making a mistake for you. To make your own object you will have to use the java.io.ObjectOutputStream.
For most developers who create objects in Java, there are two kinds of things you will have to do to make them Serializable.
First of all, you have to make your object Serializable to be able to serialize it (for example, in a message queue). When you do that, you will have to mark the object as Serializable.