Understanding the difference between shallow copy and deep copy in Java really changed how I think about object handling and memory. A shallow copy duplicates the reference — meaning changes in one object can unexpectedly affect another. On the other hand, a deep copy creates an entirely independent object with its own memory allocation. This concept might seem small at first, but it becomes critical when working with complex data structures, real-world applications, and avoiding unintended side effects. Key takeaway: Always be clear whether you're copying data or just references. #Java #Programming #Learning #DSA #SoftwareDevelopment
Java Shallow vs Deep Copy: Understanding Object Handling
More Relevant Posts
-
Day 38 of Learning Java Today, I explored how a class executes inside the JVM (Java Virtual Machine). Understanding this lifecycle really helped me see what happens behind the scenes when we run a Java program. 🔹 Class Loading • The JVM loads the class into memory • It brings the ".class" file into the system 🔹 Linking Phase • Verification → Checks bytecode for errors • Preparation → Allocates memory for static variables (default values like 0) • Resolution → Replaces symbolic references with actual memory references 🔹 Initialization • Static variables get their actual assigned values • Static blocks are executed 🔹 Execution • Methods start running and the program logic is executed 🔹 Destruction • Objects are destroyed and memory is cleaned up by the Garbage Collector Static variables first get default values during preparation, and later their actual values during initialization. Thanks to my mentor Ashim Prem Mahto for the clear explanations and for always clearing my doubts. #Java #JVM #LearningJourney #Programming #SoftwareDevelopment #BackendDevelopment #CodingLife #JavaDeveloper #TechLearning #StudentLife
To view or add a comment, sign in
-
-
Day 65 of #100DaysOfLeetCode 💻✅ Solved “Majority Frequency Group” problem in Java. Approach: • Created a frequency array of size 26 for all characters • Counted occurrences of each character in the string • For each unique frequency, counted how many characters share that frequency • Selected the frequency with the highest group size • In case of tie, chose the higher frequency • Built the result string with characters having the selected frequency Performance: ✓ Runtime: 5 ms (Beats 57.84% submissions) ✓ Memory: 44.51 MB (Beats 72.88% submissions) Key Learning: ✓ Practiced frequency grouping techniques ✓ Learned how to handle tie-breaking conditions ✓ Strengthened logic building with nested loops and conditions Learning one problem every single day 🚀 #Java #LeetCode #DSA #Strings #Hashing #ProblemSolving #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
🔹 Title: Solving “Plus Minus” Problem in Java 📊 🔹 Description: Today I solved the Plus Minus problem, where the goal is to calculate the ratios of positive, negative, and zero values in an array. The challenge was not just counting the values, but also formatting the output correctly to 6 decimal places. 💡 Approach: Traverse the array and count positives, negatives, and zeros Divide each count by the total number of elements Print results using precise formatting 🔹 What I learned: ✔ Importance of output formatting ✔ Handling edge cases (like zeros) ✔ Writing clean and efficient Java code Consistency in practicing such problems really strengthens core programming skills. 🚀 #Java #Coding #ProblemSolving #Programming #DataStructures
To view or add a comment, sign in
-
-
🚀 100 Days Java + DSA Challenge | Day 2 Today’s focus was on strengthening my programming fundamentals by covering: 🔹 Operators in Java (Arithmetic, Relational, Logical, Assignment) 🔹 Conditional Statements (if, if-else, nested if, switch) Understanding how operators work and how decisions are made in code is essential for building strong logic. These concepts are the backbone of problem-solving in Data Structures and Algorithms. 💡 Practiced writing multiple programs using conditions and improved my logical thinking step by step. Consistency is the key — small progress every day leads to big results. #100DaysOfCode #Java #DSA #LearningJourney #Coding #SoftwareDevelopment
To view or add a comment, sign in
-
🚀 Day 57 of My Java DSA Journey Today I worked on a classic Dynamic Programming problem: 💡 Subset Sum Problem 🧠 Approach: • Used recursion with memoization • At each step, decided whether to include or exclude an element • Stored intermediate results to optimize performance 🔍 Key Insight: A subset with sum k exists if: We can form k without current element OR We can form k - arr[i] including current element ⚡ What I learned: • DP pattern similar to Knapsack • Importance of proper memoization • Handling boolean DP states 🔥 Complexity: • Time: O(n × k) • Space: O(n × k) 🎯 Takeaway: Many DP problems are variations of a few core patterns. #Day57 #90DaysOfCoding #DSA #DynamicProgramming #Java
To view or add a comment, sign in
-
-
🚀 Day 10 – Race Condition & Synchronization in Java After learning multithreading, I explored a common issue: Race Condition 👉 It happens when multiple threads access and modify shared data at the same time. Example: class Counter { int count = 0; void increment() { count++; } } If multiple threads call "increment()" simultaneously: 👉 Expected: consistent count 👉 Reality: unpredictable results 💡 Why? Because "count++" is not atomic (it involves multiple steps internally) --- 👉 Solution: Synchronization synchronized void increment() { count++; } ✔ Ensures only one thread executes the method at a time ✔ Prevents data inconsistency ⚠️ Insight: Synchronization solves the problem, but excessive use can impact performance. 💡 Real takeaway: - Multithreading = powerful - But without control → leads to subtle bugs - Balance between safety and performance is key #Java #BackendDevelopment #Multithreading #Synchronization #LearningInPublic
To view or add a comment, sign in
-
🚀 **Day 10 of My DSA Journey in Java** Today’s focus was on one of the most powerful concepts in programming — **Loops** 🔁 Loops help us run a block of code multiple times, making programs more efficient, compact, and easier to debug. Here’s what I learned: 🔹 **For Loop** Understood its structure — initialization, condition, and update — and how it controls iterations. 🔹 **Nested Loops** Learned how to use loops inside loops, especially for solving pattern-based problems like star patterns ⭐ 🔹 **Jump Statements** `break` → Immediately exits the loop `continue` → Skips the current iteration and moves to the next 🔹 **While Loop** Executes as long as the condition remains true. 🔹 **Do-While Loop** Runs at least once, even if the condition is false — a unique and useful behavior. 💡 **Key Takeaway:** Loops are essential for writing efficient code and solving repetitive problems with ease. #Java #DSA #LearningInPublic #Programming #100DaysOfCode #JavaDeveloper
To view or add a comment, sign in
-
🚀 Day 48 of My Java Learning Journey Today, I explored one of the most important concepts in Java – Collection Framework 💡 📌 What I Learned: Collection Framework is a set of classes and interfaces used to store and manipulate data efficiently It was introduced in JDK 1.2 by Josh Bloch Acts as an alternative to Data Structures in Java 📊 Key Components: Interfaces → List, Set, Queue, Map Classes → ArrayList, LinkedList, HashSet, HashMap 🔥 Why Collections? ✔ Dynamic size (no fixed length like arrays) ✔ Inbuilt methods (add, remove, etc.) ✔ Efficient data handling ✔ Reduces coding effort 💻 Key Features: Allows heterogeneous data Maintains insertion order (List) Allows duplicates (List) Improves performance in real-world applications 📈 Takeaway: Collection Framework is a must-know concept for interviews and real-time development. Almost every Java application uses it! #Day48 #Java #CollectionsFramework #JavaDeveloper #LearningJourney #Coding #Programming
To view or add a comment, sign in
-
-
Day 44-What I Learned In a Day(JAVA) Today I revised pattern programming in Java to strengthen my core logic and understanding of loops. What I practiced: • Star patterns • Number patterns • Pyramid patterns • Inverted patterns • Nested loop logic Pattern programming helped me improve: • Loop control (for/while) • Logical thinking • Understanding of rows & columns Every pattern I solve makes my logic stronger step by step. Consistency is the key #Java #CodingJourney #PatternProgramming #Learning #StudentDeveloper
To view or add a comment, sign in
-
💻 Day 19 of My Java Journey Today I explored Generics, and it made Java feel much cleaner. Instead of writing separate code for different data types, generics allow us to write one reusable piece of code. Using <T> as a placeholder, we can handle multiple data types safely without worrying about runtime errors. This is one of those concepts that improves both code quality and flexibility. Learning something new every day 🚀 #Java #Programming #LearningInPublic #CodingJourney
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development