What is object deep copy and shallow copy? - Java

What is object deep copy and shallow copy?

Deep copy:

- In deep copy the copy operations would respect the semantics of the object.
- It copies all the fields and makes the copy of the dynamically allocated memory pointed to the field.
- It occurs when an object is copied along with the objects to which it refers.
- For example, copying an object along with the objects to which it refers to.

Shallow copy:

- A shallow copy copies an object without its contained objects.
- It is a bitwise copy of an object.
- The creation of a new object has the exact copy of the values in the original object.
- Fields of any object are references of the other objects.
- Only the reference address are copied i.e. the memory address is copied.
What is dynamic variable in java and where do we use them?
The variables that are initialized at run time is called as dynamic variable...
Explain the advantages of JTA over JTS
Java Transaction API is simple and more flexible to use. There are two levels in JTA API...
What is a resource leak?
Usually all operating systems have limitations for using the number of file handles, sockets etc., which can be open...
Post your comment