4)shallow copy- If we implement Cloneable interface, we must override clone method and call super.clone() from it, invoking super.clone() will do shallow copy.

5) Deep copy - We need to provide custom implementation of clone method for deep copying. When the copied object contains some other object its references are copied recursively in deep copy. When you implement deep copy be careful as you might fall for cyclic dependencies

The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x

will be true, and that the expression:

x.clone().getClass() == x.getClass()

\will be true, but these are not absolute requirements. While it is typically the case that:

x.clone().equals(x)

will be true, this is not an absolute requirement.

8) According to javaDocs -the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass()

Shallow copy >

Let’s say we want to shallow copy emp object using clone method.

In shallow copy, different object is created after cloning (i.e. clonedEmp is created from emp) but member variables keep on referring to same object (i.e. name and map).

Dozer is a Java Bean to Java Bean mapper that recursively copies data from one object to another, it is an open source mapping framework that is robust, generic, flexible, reusable, and configurable.

7) Deep cloning using Serialization and deserialization- Simply serialize object by creating object ofObjectOutputStream and then using its writeObject method. And then deserializing the object. (As done in above program)

In serialization and deserialization process, different object is created after deserialization ( i.e. deSerializedEmp is created from emp) , also member variables starts referring to different objects (i.e. name and map).