• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is cloning in java

 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

What is cloning in java...Didnt fing any good article in google to help me out....A smalll example would help a lot to understand....
 
Ranch Hand
Posts: 128
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this example might help you understand better.
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If deepak does not mind, may i ask why do we need cloning/what are its applications ?
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raghavendra Shockley wrote:If deepak does not mind, may i ask why do we need cloning/what are its applications ?


Any time you need a copy of an object.

The usual example is an array. Arrays are quite nice, but they have one major problem: they're mutable. So if I simply hand off an array of mine to some nefarious method; it could then alter the contents of my array and screw up my program.

On the other hand, if I hand over a copy of my array, the naughty method can do whatever it likes with the copy, and my array will be untouched.

Does that help?

Winston
 
deepak carter
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GOT IT.....

Can you explain swallow and deep cloning in the same way.if i can explain like this...i would surely get a good job....


and which one is better swallow or deep
 
Marshal
Posts: 79462
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Joseph Mokenela wrote:I think this example might help you understand better.

No, that is a very poor example.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

deepak carter wrote:GOT IT.....

Can you explain swallow and deep cloning in the same way.if i can explain like this...i would surely get a good job....



Shallow cloning is what the clone() method does by default. It makes a copy of the object, but it does not copy any objects that our original object refers to.

Deep cloning is when we make copies of all the objects referred to, and all the objects they refer to, and so on, so that an entire object graph is copied.

and which one is better swallow or deep



Which is better, a hammer or a screwdriver?
 
Been there. Done that. Went back for more. But this time, I took this tiny ad with me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic