File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between Shallow copy and Deep Copy in Java

 
Mahi Ranga
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Allways wanted to do this

http://lmgtfy.com/?q=What+is+shallow+copy+and+deep+copy+in+Java%3F&l=1
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch
 
Dan Din
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good one, Pegel!
 
Dawid Skrzypczynski
Ranch Hand
Posts: 52
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic