This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
It depends on how much of the object's 'children' and 'relationships you want. Think of how many XML parsing libraries work, often they give you a choice, if you clone a Node they give you a basic copy of the Node (Attribute information, Id etc) or a copy of the Node including its entire tree structure.
Could you give some other example which will explain more ?
I can give it a shot ...
Let us take a web application that intends to provide some monitoring of the user sessions. Any administrator that logs into the system can view the current user sessions and what actions are being performed. The admin can take a snapshot of a user session for records. Now, in order to take a snapshot the current state of the user session, which let us say is held by the object UserSession, needs to be copied. One can not use the same object because the user session is still active and hence can modify the state and hence making the snapshot dirty. In such a scenario you need to take a "copy" of the entire user session object that may have contained objects till any depth. So, in this process you will scan the entire object and keep on copying any state of the object into a brand new instance. This process is called "deep copy" and when implemented as a clone, you might as well call it a deep clone.
Shallow copy can be useful in cases where the contained objects inside the copied object are immutable. So, there is no point in making a copy of these objects as they can not be changed. So, all you need to do is just create a new instance of the main object and be done with it.