Deep Cloning vs Shallow Cloning in Java (With Examples)

📰 Medium · Programming

Learn the difference between shallow and deep cloning in Java and how to implement them using copy constructors and other methods.

intermediate Published 30 Apr 2026
Action Steps
  1. Create a shallow copy of an object using the clone() method in Java.
  2. Implement a deep copy of an object using a copy constructor in Java.
  3. Use the Serializable interface to create a deep copy of an object in Java.
  4. Compare the differences between shallow and deep cloning in Java.
  5. Apply shallow and deep cloning techniques to real-world problems in Java.
Who Needs to Know This

Software engineers and developers who work with Java can benefit from understanding the concepts of shallow and deep cloning to create copies of objects without affecting the original data.

Key Insight

💡 Shallow cloning creates a new object with shared internal references, while deep cloning creates a completely independent copy of the original object.

Share This
💡 Learn the difference between shallow and deep cloning in Java! #Java #Cloning

Key Takeaways

Learn the difference between shallow and deep cloning in Java and how to implement them using copy constructors and other methods.

Full Article

Title: Deep Cloning vs Shallow Cloning in Java (With Examples)

URL Source: https://medium.com/@sunil17bbmp/deep-cloning-vs-shallow-cloning-in-java-with-examples-5da59471d11b?source=rss------programming-5

Published Time: 2026-04-30T00:31:01Z

Markdown Content:
# Deep Cloning vs Shallow Cloning in Java (With Examples) | by Code With Sunil | Code Smarter, not harder | Apr, 2026 | Medium

[Sitemap](https://medium.com/sitemap/sitemap.xml)

[Open in app](https://play.google.com/store/apps/details?id=com.medium.reader&referrer=utm_source%3DmobileNavBar&source=post_page---top_nav_layout_nav-----------------------------------------)

Sign up

[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40sunil17bbmp%2Fdeep-cloning-vs-shallow-cloning-in-java-with-examples-5da59471d11b&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)

[](https://medium.com/?source=post_page---top_nav_layout_nav-----------------------------------------)

Get app

[Write](https://medium.com/m/signin?operation=register&redirect=https%3A%2F%2Fmedium.com%2Fnew-story&source=---top_nav_layout_nav-----------------------new_post_topnav------------------)

[Search](https://medium.com/search?source=post_page---top_nav_layout_nav-----------------------------------------)

Sign up

[Sign in](https://medium.com/m/signin?operation=login&redirect=https%3A%2F%2Fmedium.com%2F%40sunil17bbmp%2Fdeep-cloning-vs-shallow-cloning-in-java-with-examples-5da59471d11b&source=post_page---top_nav_layout_nav-----------------------global_nav------------------)

![Image 1](https://miro.medium.com/v2/resize:fill:32:32/1*dmbNkD5D-u45r44go_cf0g.png)

Member-only story

# Deep Cloning vs Shallow Cloning in Java (With Examples)

[![Image 2: Code With Sunil | Code Smarter, not harder](https://miro.medium.com/v2/resize:fill:32:32/1*-lvt1bxU-jKgyYc2iDJ-Vg.jpeg)](https://medium.com/@sunil17bbmp?source=post_page---byline--5da59471d11b---------------------------------------)

[Code With Sunil | Code Smarter, not harder](https://medium.com/@sunil17bbmp?source=post_page---byline--5da59471d11b---------------------------------------)

Follow

6 min read

·

1 hour ago

[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fvote%2Fp%2F5da59471d11b&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40sunil17bbmp%2Fdeep-cloning-vs-shallow-cloning-in-java-with-examples-5da59471d11b&user=Code+With+Sunil+%7C+Code+Smarter%2C+not+harder&userId=5179ca89fe2c&source=---header_actions--5da59471d11b---------------------clap_footer------------------)

50

[](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2F_%2Fbookmark%2Fp%2F5da59471d11b&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40sunil17bbmp%2Fdeep-cloning-vs-shallow-cloning-in-java-with-examples-5da59471d11b&source=---header_actions--5da59471d11b---------------------bookmark_footer------------------)

[Listen](https://medium.com/m/signin?actionUrl=https%3A%2F%2Fmedium.com%2Fplans%3Fdimension%3Dpost_audio_button%26postId%3D5da59471d11b&operation=register&redirect=https%3A%2F%2Fmedium.com%2F%40sunil17bbmp%2Fdeep-cloning-vs-shallow-cloning-in-java-with-examples-5da59471d11b&source=---header_actions--5da59471d11b---------------------post_audio_button------------------)

Share

Learn to create shallow copy, deep copy and using copy constructors in Java.

Press enter or click to view image in full size

![Image 3](https://miro.medium.com/v2/resize:fit:700/1*4MTqTfXqYhWFy-IGhgxoRw.png)

Copying objects is a fundamental concept in Java that every developer should understand. When we create a copy of an object, we create a new object that has the same state as the original one. This concept is useful when we want to duplicate objects without affecting the original data.

Java provides two main approaches for copying objects: shallow copying and deep copying. In shallow copying, a new object is created, but the internal references are shared with the
Read full article → ← Back to Reads