🚀 Day 13 – Core Java TAP Academy | Pass by Value vs Pass by Reference 💻🔥 Today’s session was one of the most important foundational concepts in Java — understanding the difference between Pass by Value and Pass by Reference 🧠⚙️ This concept is not just theoretical. It directly impacts how memory works, how objects behave, and how real-world applications are built. 📌 🔹 Pass by Value In Java, primitive data types follow Pass by Value. ✔️ The actual value is copied ✔️ Changes made to the new variable do NOT affect the original variable ✔️ Both variables are stored separately in memory Example: int a = 1000; int b = a; b = 2000; Here, modifying b does NOT change a because only the value was copied — not the memory reference. 🧠 Key Insight: Each variable has its own independent memory space. 📌 🔹 Pass by Reference (Object Reference Passing) When working with objects, Java passes the reference (address) of the object. ✔️ Multiple reference variables can point to the same object ✔️ Changes made using one reference affect the same object ✔️ Memory is shared at the object level Example: Car a = new Car(); Car b = a; b.name = "KIA"; Here, both a and b point to the same object in Heap memory. Changing through b will reflect when accessed through a. 🧠 Key Insight: One object ➝ Multiple references ➝ Shared memory behavior. 🔥 Why This Concept is Critical? ✔️ Foundation for Object-Oriented Programming ✔️ Essential for understanding Heap & Stack memory ✔️ Frequently used in Collections & Advanced Java ✔️ Helps prevent logical and memory-related mistakes Understanding this concept changed how I look at objects and memory in Java. It’s not just about writing code — it’s about understanding what happens internally in RAM 🧠⚡ 📈 Reality Check: What we learn in class is only 50%. Practicing outside the class is what creates real improvement. Consistent practice ➝ Better clarity ➝ Stronger interviews ➝ Faster placement 🚀 On to the next concept tomorrow! 🔥 Trainer:Sharath R #Day13 #CoreJava #Java #PassByValue #PassByReference #ObjectOrientedProgramming #HeapMemory #StackMemory #TapAcademy #FullStackJourney #JavaDeveloper #LearningInPublic 💻🚀
Java Pass by Value vs Pass by Reference Explained
More Relevant Posts
-
Java Full Stack Development – Day 13 | Tap Academy Topic Covered: 🔹 Pass by Value vs Pass by Reference 🔹 Different Types of Methods in Java 🔹 Memory Segments in Java (Stack, Heap, Static) 1️⃣ Pass by Value ✔ In Java, primitive variables are passed by value. ✔ A copy of the variable is sent to the method. ✔ Changes inside the method do not affect the original value. Example: int a = 1000; int b; b = a; System.out.println(a); System.out.println(b); Output 1000 1000 2️⃣ Pass by Reference (Objects) ✔ Object reference is passed to methods. ✔ Changes made to the object affect the original object. Example: Car c1 = new Car(); c1.name = "MARUTHI"; c1.noOfSeats = 5; c1.cost = 8.66f; System.out.println(c1.name); System.out.println(c1.noOfSeats); System.out.println(c1.cost); Output MARUTHI 5 8.66 3️⃣ Different Types of Methods Java methods are classified into 4 types: 1️⃣ No Input – No Output 2️⃣ No Input – Output 3️⃣ Input – No Output 4️⃣ Input – Output These help in structuring programs and improving code reusability. 4️⃣ Memory Segments in Java Java uses different memory areas: Static Segment • Stores static variables. Stack Segment • Stores method calls and local variables. • Each method has its own stack frame. Heap Segment • Stores objects created using new. Example Concept: class Calculator { int a = 50; int b = 40; void add() { int c = a + b; System.out.println(c); } } ✔ Object stored in Heap ✔ Method execution stored in Stack Conclusion Today’s session helped in understanding how Java handles data passing, method types, and memory management, which are fundamental concepts for becoming a strong Java Full Stack Developer. #Java #JavaFullStack #TapAcademy #Programming #JavaDeveloper #CodingJourney #LearnJava #FullStackDeveloper #SoftwareDevelopment #JavaLearning
To view or add a comment, sign in
-
-
🚀 Understanding the Internal Execution Flow in Java. Ever wondered what really happens under the hood when you run a Java program? It is much more than just the main method!. In my latest learning session at TAP Academy with Sharath R sir, I learned about the seven essential elements of a Java class: static variables, static blocks, static methods, instance variables, instance blocks, instance methods, and constructors. Here are the key takeaways: 🔹 Static vs. Instance: A fundamental rule is that static members belong to the class, while instance members belong to the object. 🔹 The Class Loader: When the JVM needs a class, it calls its "closest friend," the Class Loader, to locate and load the class into the code segment. 🔹 Order of Execution: Java execution follows a strict sequence. It starts with static variables and static blocks during class loading, long before the main method or any object creation occurs. 🔹 The "Illegal" Access Rule: You cannot access instance variables from a static block or method. Why? Because static members are initialized during class loading, at which point the object (and its instance variables) does not even exist yet. Understanding the internal memory flow—from the static segment to the heap and stack—is the first step toward mastering Java's object-oriented pillars. #Java #Programming #SoftwareDevelopment #oops #ObjectOrientedProgramming #TechLearning #Tap Academy
To view or add a comment, sign in
-
-
🚀 Day 14 – Java Full Stack Journey | Pass by Value vs Reference Behavior in Java Today’s focus was on a very important concept in Java: 👉 Pass by Value (Primitive Types) 👉 Reference Behavior with Objects Understanding this clearly is essential for mastering Object-Oriented Programming. 🔹 1️⃣ Pass by Value (Primitives) int a = 1000; int b = a; b = 2000; ✔ A copy of the value is passed ✔ a and b are completely independent ✔ Changing b does NOT affect a Final Values: a → 1000 b → 2000 This is called Pass by Value because only the value is copied. 🔹 2️⃣ Reference Behavior (Objects) Car a = new Car(); Car b = a; ✔ Only one object is created in Heap ✔ a and b both point to the same object ✔ Multiple references → Single object If we modify using b: b.name = "KIA"; Then accessing with a.name will also show "KIA". Why? Because both references point to the same memory location. 🔹 Memory Understanding Primitive variables → Stored in Stack → Independent copies Objects → Stored in Heap References → Stored in Stack → Point to Heap object One object can have multiple references. Any modification through one reference reflects for all. 💡 Key Learning • Primitives → Value copy • Objects → Reference copy • One object → Many references possible • Understanding memory makes debugging easier Today’s learning strengthened my clarity in Object-Oriented Programming fundamentals. Day 14 Complete ✔ #Day14 #Java #CoreJava #PassByValue #PassByReference #OOPS #HeapAndStack #JavaDeveloper #FullStackJourney #LearningInPublic TAP Academy
To view or add a comment, sign in
-
-
🚀 Day A9 at Tap Academy – Understanding Variables in Java ☕ Today’s session was all about one of the most fundamental concepts in Java – Variables. Mastering variables is the first step toward building powerful Java programs. Let’s break it down in a simple way 👇 📦 What is a Variable? A variable is like a container used to store data in memory. Each variable must belong to a specific data type, which defines what kind of data it can store. Syntax: dataType variableName; Example: int a; 🔹 Types of Variables in Java 1️⃣ Instance Variables Declared inside the class but outside methods Memory allocated in the Heap segment Automatically get default values from JVM Accessible throughout the entire class Example: Java class Student { int id; // instance variable } 2️⃣ Local Variables Declared inside methods or blocks Memory allocated in the Stack segment ❌ Do NOT get default values from JVM Must be initialized by programmer Accessible only within the method/block Example: Java void display() { int marks = 90; // local variable } 🧠 JRE Memory Structure (Runtime Memory Segments) JRE (Java Runtime Environment) allocates memory in RAM using four segments: 📄 Code Segment – Stores compiled bytecode 📌 Static Segment – Stores static variables 🧺 Heap Segment – Stores instance variables & objects 📚 Stack Segment – Stores local variables & method calls 🎯 Default Values of Instance Variables Data Type. Default Value int. 0 float/double. 0.0 char. empty (\u0000) boolean. false String / Array / Object. null ⚠️ Local variables do NOT get default values. ⚖️ Difference Between Instance and Local Variables 👉Feature. Instance Variable. Local Variable 👉Declared. Inside class. Inside method 👉Memory. Heap. Stack 👉Default Value Provided by Jvm Not provided 👉Scope. Entire class. Only method/block 👉Access. through objects. Only within method 💡 Key Takeaway Variables are the foundation of Java programming. Understanding their types, memory allocation, scope, and default values helps in writing efficient and error-free programs. ✨ Every line of code becomes meaningful when you understand where and how data is stored. #TapAcademy #Java #Variables #JVM #JRE #Programming #JavaDeveloper #CodingJourney #LearnJava #SoftwareDevelopment #CoreJava
To view or add a comment, sign in
-
-
🚀 Day 16 | Core Java Learning Journey 📌 Topic: static Keyword & Access Modifiers (Java Keywords – Part 1) Today, I learned how Java controls class-level behavior and visibility using the static keyword and Access Modifiers. 🔹 static Keyword in Java 1️⃣ Static Variable – Belongs to the class, not objects – Shared among all instances (common property) 2️⃣ Static Method – Can be called without creating objects – Accessed using ClassName.methodName() 3️⃣ Static Block – Executes once during class loading – Used for static initialization 4️⃣Static Nested Class – A class declared static inside another class – Does not require outer class instance – Used for logical grouping & memory efficiency 🔹 Access Modifiers in Java Access modifiers define where members are visible. 1️⃣ public – Accessible from anywhere 2️⃣ private – Accessible only within the same class 3️⃣protected – Accessible within the same package – Also accessible in subclasses (even outside package) 4️⃣ default (no modifier) – Accessible only within the same package 📌 Key Takeaway ✔️ static → Controls class-level sharing & behavior ✔️ Access Modifiers → Control visibility & encapsulation ✔️ Both are essential for clean & secure class design Special thanks to Vaibhav Barde Sir for simplifying core concepts 💻 #CoreJava #JavaLearning #OOP #StaticKeyword #AccessModifiers #JavaDeveloper #LearningJourney
To view or add a comment, sign in
-
-
Day 29 of Sharing What I’ve Learned 🚀 this Keyword in Java — Referring to the Current Object 🎯 Sometimes inside a class, parameter names and instance variables look exactly the same… How does Java know which one you mean? 🤔 👉 That’s where the this keyword comes in. 🔹 What Is this? this is a reference variable that points to the current object (the object whose method or constructor is being executed). 👉 In simple terms: “this refers to the object that is currently working.” 🔑 Why Do We Need this? When local variables (like constructor parameters) have the same name as instance variables, the local variable “shadows” the instance variable. Without this, Java will use the local variable only ⚠️ ✔ this removes that confusion ✔ Explicitly accesses instance variables ✔ Improves readability 🔧 Example — Without this (Problem) class Customer { private int id; Customer(int id) { id = id; // Assigns parameter to itself ❌ } } 👉 Instance variable id remains uninitialized! 🔧 Example — Using this (Correct) class Customer { private int id; Customer(int id) { this.id = id; // Refers to instance variable ✔ } } 👉 Now the object stores the correct value. 🧠 Other Uses of this 🔹 Call current object’s methods 👉 this.display(); 🔹 Pass current object as argument 👉 someMethod(this); 🔹 Return the current object 👉 return this; ⚠️ Important Notes ✔ this can be used only inside non-static methods/constructors ✔ Not usable inside static context ✔ Improves clarity when variables share names 🎯 Why this Matters ✔ Prevents variable shadowing bugs ✔ Makes code explicit and readable ✔ Helps manage object state safely ✔ Essential for clean OOP design 🧠 Key Takeaway Objects don’t just hold data… 👉 They must know how to refer to themselves. The this keyword gives every object its own identity inside the class 💡 #Java #CoreJava #OOP #ThisKeyword #ObjectOrientedProgramming #Programming #BackendDevelopment #InterviewPreparation #Day29 Grateful for the guidance from Sharath R, Harshit T, TAP Academy
To view or add a comment, sign in
-
-
🚀 Learning Update: Core Java — Mutable Strings & Advanced String Concepts Today’s session helped me dive deeper into Java Strings, especially the concepts of mutable strings (StringBuffer & StringBuilder) and how they work internally in memory. 📌 Key Takeaways: ✅ Learned the difference between Immutable vs Mutable Strings • Immutable → Created using String class (cannot be modified) • Mutable → Created using StringBuffer and StringBuilder (can be modified) ✅ Understood StringBuffer concepts: • Default capacity = 16 • Dynamic resizing using formula (current capacity × 2) + 2 • Methods like append(), delete(), capacity(), length(), and trimToSize() ✅ Explored StringBuilder vs StringBuffer: • StringBuffer → Thread-safe (synchronized) • StringBuilder → Faster but not thread-safe • Learned when to use each based on application needs ✅ Learned about String Tokenizer and how strings can be split into tokens, along with why modern applications prefer the split() method instead. 💡 Important Insight: Understanding how memory, capacity, and mutability work internally gives a much stronger foundation than just writing syntax. Consistent practice in IDE tools and coding environments is essential to perform well in interviews and real-world development. #Java #CoreJava #Programming #CodingJourney #LearningUpdate #SoftwareDevelopment #StudentDeveloper @TAP Academy
To view or add a comment, sign in
-
-
🚀 Learning Core Java – Understanding this() Constructor Chaining Today I learned an important concept in Java constructors — this() constructor chaining. In Java, this() is used to call another constructor of the same class. This technique is called local constructor chaining, and it helps reduce code duplication when multiple constructors perform similar initialization. ⸻ 🔹 What is this()? this() is used to invoke another constructor within the same class. Instead of repeating initialization logic in multiple constructors, we can reuse existing constructor logic by calling it using this(). ⸻ 🔹 Important Rules of this() ✔ this() must always be the first statement inside a constructor. ✔ It is used only within constructors. ✔ It helps chain constructors inside the same class. ✔ It improves code reusability and readability. ⸻ 🔹 Why Use Constructor Chaining? Without constructor chaining, we may repeat the same initialization code in multiple constructors. Using this() allows one constructor to reuse another constructor’s logic, making the code cleaner and easier to maintain. ⸻ 🔎 Key Insight this() helps maintain clean and reusable constructor logic while ensuring that object initialization happens in a structured way. Understanding constructor chaining is an important step in mastering object initialization and class design in Java. Excited to keep strengthening my Core Java fundamentals! 🚀 #CoreJava #JavaProgramming #ConstructorChaining #JavaDeveloper #ObjectOrientedProgramming #ProgrammingFundamentals #LearningJourney #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 *Understanding Mutable Strings in Java* 🚀 In Java, strings are immutable by default, meaning once created, their values can't be changed. But what if you need to modify strings frequently? That's where *mutable strings* come in! 🔹 *Why Mutable Strings?* Mutable strings allow you to change their content without creating a new object, improving performance and memory efficiency when you need to modify strings often. 🔹 *StringBuilder vs. StringBuffer* Java provides two classes for creating mutable strings: - *StringBuilder*: Not thread-safe, but faster. Ideal for single-threaded environments. - *StringBuffer*: Thread-safe (synchronized), making it suitable for multi-threaded environments, though slightly slower than StringBuilder. 🔹 *Key Differences* - *Synchronization*: StringBuffer is synchronized, StringBuilder isn't. - *Performance*: StringBuilder is generally faster due to lack of synchronization overhead. - *Use Cases*: Choose StringBuilder for single-threaded contexts, StringBuffer for multi-threaded ones. 🔹 *Example Usage* // Using StringBuilder StringBuilder sb = new StringBuilder("Hello"); sb.append(" World"); System.out.println(sb.toString()); // Outputs: Hello World // Using StringBuffer StringBuffer sbf = new StringBuffer("Hello"); sbf.append(" World"); System.out.println(sbf.toString()); // Outputs: Hello World 💡 *Learning from Tap Academy* I'm grateful to Tap Academy for helping me deepen my understanding of Java concepts like mutable strings. Their teaching approach makes complex topics easy to grasp! #Java #StringBuilder #StringBuffer #MutableStrings #TapAcademy #Programming #SoftwareDevelopment TAP Academy
To view or add a comment, sign in
-
-
Understanding static in Java | JVM Execution Flow 📍 Learned at TAP Academy As part of my Java learning journey at TAP Academy, I explored the concept of static and how it works inside the JVM. 🔎 What happens when a Java program runs? When we execute a Java program: 1️⃣ The JVM (Java Virtual Machine) loads the class into memory. 2️⃣ While loading the first class, JVM checks for: ✅ Static variables ✅ Static blocks ✅ Static methods 3️⃣ After loading static members, JVM looks for the entry point: public static void main(String[] args) ⚡ Why is main() static? Because the JVM must call it without creating an object of the class. 💡 What is static in Java? static members belong to the class, not to objects. Memory is allocated only once in the class area. Shared among all objects of the class. 🔹 Static Variable Common property shared by all objects. Saves memory because only one copy is created. 🔹 Static Block Executes only once when the class is loaded. Used for initialization of static variables. 🎯 Understanding static helped me clearly visualize how JVM loads classes and manages memory. Grateful to TAP Academy for strengthening my Java fundamentals 🙌 #Java #OOPS #JVM #TAPAcademy #Programming #LearningJourney
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