Hi,
Hope you are all doing great. Let's learn together.
Join Telegram: 📲 https://t.me/contactajoydebnath
Chapters ❤
0:00 Introduction
00:55 What is cloning in Java?
03:27 Code implementation of cloning in Java
19:13 Shallow Copy in Java
36:47 Deep Copy In Java
Note:
Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year 1995. James Gosling is known as the father of Java. Before Java, its name was Oak. Since Oak was already a registered company, James Gosling and his team changed the name from Oak to Java.
Video Links --
Exception, Custom Exception, throw, throws -- • Exception, Custom Exception, throw, throws...
Exception, try, catch, finally -- • Exception, Propagation try, catch, finally...
Exception, Exception Hierarchy, Call Stack, Propagation. Bengali-Ep:22 -- • Exception, Exception Hierarchy, Call Stack...
Lambda Expression, Functional Interfaces, Anonymous Class. -- • Lambda Expression, Functional Interfaces, ...
Singleton Pattern. Lazy Instantiation for Multiple Threads.Part-2 Bengali-Ep:20 • Singleton Pattern. Lazy Instantiation for ...
Singleton Design Pattern in Java. Early & Lazy Instantiation Bengali-Ep:19 : • Singleton Design Pattern Java. Early & Laz...
HashSet, Its Methods & How It Works Internally in Java : • HashSet, Its Methods & How It Works Intern...
HashSet & How It Works Internally in Java. -- • HashSet & How It Works Internally in Java....
LinkedList, Methods & How It Works Internally in Java. -- • LinkedList, Methods & How It Works Interna...
ArrayList, ListIterator, How It Works Internally -- • ArrayList, ListIterator, How It Works Inte...
Collection Framework ---- • Collections Framework, Collection & Iterat...
'super' keyword - • 'super' keyword in Java. Bengali-Ep:13 #b...
'this' keyword - • 'this' keyword in Java. Bengali-Ep:12 #be...
Final Keyword - • Final keyword, Final variable, method, cla...
Static Keyword, Static variable, block, method, nested class - • Static keyword, Static variables, block, m...
Access Modifier. Private, Public, Default, Protected -- • Access Modifier. Private, Public, Default,...
Encapsulation, Data Hiding, Setter-Getter method, JavaBean Class -- • Encapsulation, Data Hiding, Setter-Getter ...
Polymorphism, Method and Constructors Overloading, Method Overriding -- • Polymorphism, Method & Constructors Overlo...
Inheritance, Is-A relationship, the problem with multiple inheritances -- • Inheritance, 'IS-A' relationship, multiple...
Abstraction, Interface -- • What is Abstraction? Interface Implementat...
Abstraction, Abstract Class - • What is Abstraction? Abstract Class Implem...
What are Class, Object, Method, and Constructors- • What is Class, Object, Method, Constructo...
Environment Setup and why we need to set path in environment variable -- • Environment Setup. Why do you set a Java p...
First Java Program - "Hello World" -- • First Java Programming "Hello World" Print...
Document Link -
https://docs.google.com/document/d/1v...
Like, Comment, Share, and Subscribe.
Thank you again.
STS Link:
https://spring.io/tools
JDK Link:
https://www.oracle.com/java/technolog...
Cloning
1. Cloning is a process of creating a replica or copy of a Java object.
2. clone() method present in Java.lang.Object is used to create a copy or replica of an object.
3. Java objects which implement a Cloneable interface are eligible to use the clone() method.
4. The clone() method in the Object class is protected in nature, so not all classes can use the clone() method.
5. You need to implement the Cloneable interface and override the clone method.
Deep and Shallow Copy
Shallow Copy
1. The default implementation of the clone method creates a shallow copy of the source object, which means a new instance of type Object is created, it copies all the fields to a new instance and returns a new object of type ‘Object’.
2. This Object explicitly needs to be typecast in the object type of the source object.
3. If the source object contains any references to other objects then the new instance will have only references to those objects, a copy of those objects(Reference filed in Source Object) is not created.
4. This means if we make changes in shallow copy then changes will get reflected in the source object. Both instances are not independent.
Deep Copy
1. The deep copy of an object will have an exact copy of all the fields of the source object like a shallow copy.
2. But unlike sallow copy, if the source object has any reference fields, then a replica of the object(Reference Object present as a field in the source object) is created by calling the clone method.
3. This means that both source and cloned objects are independent of each other. Any change made in the cloned object will not impact the source object.