File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Difference between Shallow copy and Deep Copy in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Difference between Shallow copy and Deep Copy in Java" Watch "Difference between Shallow copy and Deep Copy in Java" New topic
Author

Difference between Shallow copy and Deep Copy in Java

Mahi Ranga
Ranch Hand

Joined: Jan 27, 2011
Posts: 35
Hi Sir/Mam,

Explain What is the Difference between Shallow copy and Deep Copy in Java.please provide some examples.

Regards,
Mahi.
pegel van de Wiel
Greenhorn

Joined: Jun 09, 2011
Posts: 3

Allways wanted to do this

http://lmgtfy.com/?q=What+is+shallow+copy+and+deep+copy+in+Java%3F&l=1
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38349
    
  23
Welcome to the Ranch
Dan Din
Greenhorn

Joined: Jun 06, 2011
Posts: 12
Good one, Pegel!
Dawid Skrzypczynski
Ranch Hand

Joined: Jun 08, 2011
Posts: 52
Hi,

- Shallow copy means copy only intermediate objects, pointers, references, handles etc and is created very fas.
- copies this object refer to the same object, change in its state will be visible in all copies of this object.

- deep copy means real object copy, it take more times and resources but object and his copy are independent of each.
- Object changes have no effect on the copies


Sorry for my English i know that is not perfect.
pegel van de Wiel
Greenhorn

Joined: Jun 09, 2011
Posts: 3

Ok, had my fun, a little more constructive:
Dawid has said it all, but keep in mind, for the non fast (i.e. deep copy) make sure to implement Cloneable interface and override the clone() method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between Shallow copy and Deep Copy in Java