Question: What if a class is implementing serializable interface, but there's no `writeObject/readObject` method implementation anywhere in the codebase?

Will the default methods `defaultWriteObject/defaultReadObject` do the serialization or not? 

Is only marking the class with `implements Serializable` enough to serialize a class? 

If yes, then what is getting serialized and where is the state of object getting persisted?

Answer: 
> 
> What if a class is implementing serializable interface, but there's no `writeObject/readObject` method implementation anywhere in the codebase?
> 
> 
> 

It will be subject to default serialization: see below.

> 
> Will the default methods `defaultWriteObject/defaultReadObject` do the serialization or not?
> 
> 
> 

No, because they won't be invoked unless you invoke them.

> 
> Is only marking the class with `implements Serializable` enough to serialize a class?
> 
> 
> 

Yes, if you're content with default serialization: see below.

> 
> If yes, then what is getting serialized
> 
> 
> 

All the non-transient non-static member variables of the class and all its base classes that implement `Serializable,` and nothing else.

> 
> and where is the state of object getting persisted?
> 
> 
> 

Into the stream. This part of your question doesn't seem to make sense,
**1)Will the default methods defaultWriteObject/defaultReadObject do the serialization or not?**
-NO,

defaultReadObject() invokes the default deserialization mechanism, and is used when you define the readObject() method
on your Serializable class. In other words, when you have custom deserialization logic, 
you can still get back to the default serialization, which will deserialize your non-static, non-transient fields. 
For example:

```
public class TestClass implements Serializable {
    private String f2;
    private int f1;
    private transient String f3; 
    private void readObject(java.io.ObjectInputStream stream)
         throws IOException, ClassNotFoundException {
         stream.defaultReadObject(); //fills f1 and f2;
         fld3 = Configuration.getFooConfigValue();
    }
}

```

On the other hand, readObject() is used when you create the ObjectInputStream, externally from the deserialized object,
and want to read an object that was previously serialized:

```
ObojectInputStream stream = new ObjectInputStream(aStreamWithASerializedObject);
Object foo = (Foo) stream.readObject();

```

The java.io.ObjectOutputStream.defaultWriteObject() method writes the non-static and non-transient fields of the current class to this stream. This may only be called from the writeObject method of the class being serialized
This method allows to take complete control over what will be sent over the wire.
In most cases, you will just call out.defaultWriteObject() to benefit from the default serialization process.

**2)Is only marking the class with implements Serializable enough to serialize a class?**
Yes,

Any object whose class implements the java.io.Serializable interface can be made persistent with only a few lines of code.
No extra methods need to be added to implement the interface, 
however - the purpose of the interface is to identify at run-time which classes can be safely serialized, 
and which cannot. You only need to add the implements keyword to your class declaration, to identify your classes as serializable.

Now, once a class is serializable, we can write the object to any OutputStream, such as to disk or a socket connection. 
To achieve this, we must first create an instance of `java.io.ObjectOutputStream,` 
and pass the constructor an existing OutputStream instance.

```
/ Write to disk with FileOutputStream
FileOutputStream f_out = new 
    FileOutputStream("myobject.data");

// Write object with ObjectOutputStream
ObjectOutputStream obj_out = new
    ObjectOutputStream (f_out);

 // Write object out to disk
    obj_out.writeObject ( myObject );

```

**3)If yes, then what is getting serialized and where is the state of object getting persisted?**
All the non-transient non-static member variables of the class and all its base classes that implement Serializable will get persisted in some media/file.object's state to a persistence store and also rebuilding the object from the saved information when needed in the future.