Day 31 of Sharing What I’ve Learned 🚀 Difference Between this Keyword and this() in Java — Similar Name, Very Different Roles 🎯 In Java, this and this() may look almost the same… But they serve completely different purposes. ❗ 👉 Understanding this difference is essential for writing clean and correct OOP code. 🔹 this Keyword — Refers to the Current Object this is a reference variable that points to the current object. ✅ Used to access instance variables ✅ Resolves confusion between parameters and fields ✅ Can call current class methods ✅ Can pass the current object as an argument Example: class Student { int id; Student(int id) { this.id = id; // Refers to instance variable } } 👉 Here, this.id refers to the object’s field, not the parameter ✔ 🔹 this() — Calls Another Constructor in the Same Class this() is used for constructor chaining within the same class. ✅ Calls another constructor ✅ Helps reuse initialization logic ✅ Reduces duplicate code Example: class Student { int id; String name; Student() { this(0, "Unknown"); // Calls parameterized constructor } Student(int id, String name) { this.id = id; this.name = name; } } 👉 Default constructor reuses the parameterized one ✔ ⚠️ Rule: this() must be the FIRST statement in a constructor. 🧠 Key Differences at a Glance ✔ this → Refers to the current object ✔ this() → Calls another constructor ✔ this → Used inside methods/constructors ✔ this() → Used only inside constructors ✔ this → Access variables/methods ✔ this() → Enables constructor chaining 🎯 Why This Matters ✔ Prevents common beginner mistakes ✔ Helps design clean constructors ✔ Improves code readability ✔ Essential for mastering Core Java OOP 🧠 Key Takeaway Same word… different power 💡 👉 this works with objects 👉 this() works with constructors Understanding both unlocks cleaner and smarter Java code 🚀 #Java #JavaDeveloper #CoreJava #OOP #BackendDevelopment #SoftwareDevelopment #CodingJourney #InterviewPreparation #DeveloperJourney #Day31 Grateful for the guidance from Sharath R, Harshit T, TAP Academy
Java this vs this() Keyword: OOP Fundamentals
More Relevant Posts
-
🚀 Day 22 of My Java Learning Journey at TAP Academy ☕💻 Today’s topic was Flow of Execution in Java — especially understanding how static and instance members behave during program execution. This session really helped me visualize how JVM works internally. 🔹 Flow of Execution in Java When a Java program runs, the JVM first looks for the main method. Since main is static, it can execute without creating an object. ✅ Static vs Instance – What I Learned 🔹 Static belongs to the class No object creation required Called using the class name Created only once Used for efficient memory utilization 🔹 Instance belongs to the object Object creation is required Each object has its own copy 🔹 Accessibility Rules ✔ Static variables are accessible by all elements in the class ✔ Instance variables are NOT accessible directly by static methods or static blocks ✔ Static methods are called inside main() using the class name ✔ Instance variables, instance methods, and instance blocks cannot be accessed directly by static members 🔹 What JVM Checks During Execution 🔎 In the class containing the main method: JVM checks static variables JVM executes static blocks JVM recognizes static methods 🔎 In other classes (without main): JVM checks only static variables and static blocks It does NOT check static methods automatically 🔹 Static Segment (Memory Area) The static segment is also known as: Method Area Metaspace Permanent Generation (PermGen – older versions of Java) 🧠 Static blocks are mainly used to initialize static variables. 📌 Static variables are created only once per class for better memory efficiency. Understanding the flow of execution makes Java much more logical and structured. Every day, I’m not just writing code — I’m understanding how Java works behind the scenes. Consistency + Practice = Growth 📈 #Day22 #Java #JavaLearning #CoreJava #FlowOfExecution #StaticKeyword #OOP #Programming #CodingJourney #JavaDeveloper #JVM #SoftwareDevelopment #TapAcademy 🚀
To view or add a comment, sign in
-
-
🚀 Day 21 of My Java Learning Journey at TAP Academy ☕💻 Today’s topic was Static in Java — and we explored it in depth along with instance members and constructors. This session really helped me understand how Java handles memory and object behavior internally. 🔹 Understanding static in Java The static keyword is used for memory management. When a member is declared as static, it belongs to the class, not to the object. That means only one copy is created and shared across all objects. 🔹 What We Covered Today ✅ 1️⃣ Static Variables (Class Variables) Belong to the class Shared among all objects Memory allocated only once ✅ 2️⃣ Static Methods Can be called without creating an object Can directly access only static members Commonly used for utility or common logic ✅ 3️⃣ Static Block Executes only once when the class is loaded Used for static initialization 🔹 Instance Members 🔸 Instance Variables Belong to the object Each object has its own copy 🔸 Instance Methods Require object creation Can access both instance and static members 🔸 Instance Block Executes whenever an object is created Runs before the constructor 🔹 Constructors Special methods used to initialize objects Called automatically during object creation Help assign values to instance variables 💡 Key Understanding ✔ Static members → Class level ✔ Instance members → Object level ✔ Static block runs once ✔ Instance block runs every time an object is created ✔ Constructors initialize object data Today’s session gave me a clearer picture of class vs object memory structure in Java. Step by step, building a strong foundation in Core Java. 💪 Consistency + Practice = Growth 📈 #Day21 #Java #JavaLearning #CoreJava #StaticKeyword #OOP #Programming #CodingJourney #JavaDeveloper #SoftwareDevelopment #LearnToCode #DeveloperLife #TapAcademy 🚀
To view or add a comment, sign in
-
-
🚀 AI-Powered Java Full Stack Journey (Day-4) — Structuring Java Programs Revisiting Day 4 from my December learning journey with Frontlines EduTech (FLM). This session helped me understand how Java organizes everything internally — from packages to methods — in a clean and systematic way. Here’s what I strengthened 👇 🏛️ Class — The Blueprint Everything in Java starts with a class. A class is a blueprint, and objects are the real-world instances created from it. One class can create multiple objects, making applications scalable and structured. 📦 Packages — Code Organization Packages are used to group related classes. They: ✔ Keep code organized ✔ Avoid naming conflicts ✔ Improve maintainability Syntax: package mypackage; We can create custom packages or use built-in ones. 📥 Import Statement — Accessing Other Packages To use a class from another package, we use the import statement. Example: import com.org.practice.Hello; import com.org.practice.*; If classes are in the same package, import is not required. This promotes modular and reusable design. 🧮 Variables — Data Storage Variables store data in memory. Types: • Local Variables — Inside methods • Instance Variables — Object-level • Static Variables — Class-level (shared across objects) Understanding scope clarified how memory is managed. 🔁 Methods — Reusability Methods allow us to write logic once and reuse it multiple times. Example: static void sum() { System.out.println(2 + 3); } They improve readability and reduce repetition. 🚪 main() Method — Entry Point Every Java application begins execution from: public static void main(String[] args) Without main(), the program cannot run. It acts as the starting point for the JVM. 💡 Day-4 Takeaways: ✔ Clear understanding of classes and objects ✔ Importance of packages ✔ Proper use of import ✔ Variable types and scope ✔ Methods for reusability ✔ Role of main() method Day 4 strengthened my understanding of how Java maintains structure and discipline in application development. Grateful for the continuous learning journey 🚀 Thanks to Krishna Mantravadi, Upendra Gulipilli, and Fayaz S for the clear and practical explanations. #Java #FullStackDeveloper #LearningInPublic #Day4 #JavaJourney #Upskilling #Programming #FrontlinesEduTech
To view or add a comment, sign in
-
🚀 Learning Java OOP — Understanding the Object Class As a Full Stack Web Developer Intern at Tap Academy, today I explored one of the most fundamental concepts in Java: the Object Class — the root of the entire Java class hierarchy. 🔹 Every class in Java directly or indirectly inherits from the Object class 🔹 It provides common methods that are available to all Java objects 🔹 Because of this, every object automatically gets some default behaviors ✅ Important methods in the Object Class: • toString() → Converts object data into readable text • equals() → Compares two objects for equality • hashCode() → Generates a unique hash value for objects • getClass() → Returns runtime class information • clone() → Creates a duplicate of an object • wait(), notify(), notifyAll() → Used in multithreading and synchronization • finalize() → Deprecated method used earlier for garbage collection handling 💡 Key Insight: Whenever we print an object reference, Java internally calls the toString() method. That’s why overriding toString() helps display object data in a more meaningful and readable way. 📌 The Object class contains 12 methods and 1 constructor, making it the parent of all Java classes. Learning these fundamentals strengthens our understanding of Java’s Object-Oriented Programming principles and helps us write better, more efficient code. #SharathR #Java #OOP #ObjectClass #JavaProgramming #LearningJourney #JavaDeveloper #SoftwareDevelopment #TapAcademy
To view or add a comment, sign in
-
-
🚀 Day-21 at Tap Academy | Understanding Mutable Strings in Java Today’s learning was all about Mutable Strings — a very important concept when it comes to performance and memory efficiency in Java. 🔹 What is a Mutable String? A mutable string allows us to modify the content without creating a new object in memory. Java provides two classes for this purpose: 1️⃣ StringBuffer ✅ Mutable 🔒 Thread-safe (synchronized) 🧠 Best suited for multi-threaded environments Capacity Logic: Default capacity → 16 If initialized with a string → 16 + string length When capacity exceeds → 👉 (oldCapacity * 2) + 2 2️⃣ StringBuilder ✅ Mutable ⚡ Not thread-safe 🚀 Faster than StringBuffer 🧠 Ideal for single-threaded applications Capacity Logic: Same as StringBuffer Default → 16 Expansion → (oldCapacity * 2) + 2 💡 Key Takeaway: Use StringBuffer when thread safety is required Use StringBuilder when performance matters Understanding these internal details helps us write optimized, real-world Java applications 💻✨ Grateful to Tap Academy for breaking down concepts in such a practical way 🙌 Learning something new every day! 🚀 🔖 Hashtags (Focused & High-Reach): #Java #JavaDeveloper #MutableStrings #StringBuffer #StringBuilder #CoreJava #JavaProgramming #SoftwareEngineering #BackendDevelopment #ProgrammingConcepts #LearningJourney #InternshipExperience #TapAcademy #DailyLearning #TechCareers
To view or add a comment, sign in
-
-
🚀 Today’s Learning as a Full Stack Web Developer Intern at Tap Academy – Understanding static in Java Today, I deep-dived into one of the most important concepts in Java — the static keyword. The static keyword plays a crucial role in improving efficiency, memory management, and readability of Java programs. 🔹 What is static in Java? The static keyword indicates that a member belongs to the class itself, not to the objects of that class. 📌 Important Note: Static members → belong to the class Non-static (instance) members → belong to the object 📘 Members of a Java Class A class can contain: Static Variables Instance Variables Static Methods Instance Methods Static Blocks Instance Blocks Constructors 🔥 Rules of static 1️⃣ Static variables can be accessed by both static and instance members. 2️⃣ Instance variables can be accessed only by instance members. 3️⃣ Static members cannot directly access instance variables. 🟢 Static Variable ✔ Belongs to the class, not the object ✔ Initialized only once when the class is loaded ✔ Single copy shared by all objects ✔ Accessed using: ClassName.variableName; 💡 Memory allocation happens only once during class loading. 🔵 Static Method ✔ Belongs to the class ✔ Can access only static data ✔ Cannot call non-static methods directly ✔ Can be called without creating an object Example: class Car { static void milesToKm() { // conversion logic } void calcMileage() { // uses instance data } } 💡 milesToKm() is static because conversion logic does not depend on any specific car object. 🟣 Static Block ✔ Executes only once when the class is loaded ✔ Used to initialize static variables ✔ Runs before the main() method ✔ Multiple static blocks execute in sequence ⚙ JVM Order of Execution 1️⃣ Class Loading 2️⃣ Initialize Static Variables 3️⃣ Execute Static Block 4️⃣ Initialize Instance Variables 5️⃣ Execute Instance Block 6️⃣ Execute Constructor Understanding this flow is very important for interviews 🔥 🎯 Why static is Important? ✅ Saves memory (single shared copy) ✅ Useful for utility methods ✅ Improves performance ✅ Helps in centralized data handling 💬 Key Takeaway: Static members are class-level components shared across all objects, making them powerful for utility logic and memory-efficient programming. Grateful to be learning and growing every day at Tap Academy 🙌 #TapAcademy #SharathR #Java #FullStackDeveloper #InternLife #LearningJourney #Programming #JavaDeveloper #StaticKeyword #CodingLife
To view or add a comment, sign in
-
-
🚀 Mastering String Concatenation in Java! 💡 Ever wondered how strings are combined behind the scenes? 🤔 Here’s a quick and powerful breakdown of String Concatenation — the process of joining two or more strings together! 🔹 Using “+” Operator ✔ Simple & widely used ✔ Memory rules vary: • Literal + Literal → String Constant Pool • Reference combinations → Heap Area 🔹 Using .concat() Method ✔ Cleaner for method chaining ✔ Always allocates memory in the Heap Area 💻 With practical examples and memory insights, this infographic helps you clearly understand how Java handles strings internally — a must-know for writing optimized code! 📊 Also included: ✔ String comparison techniques (==, .equals(), .compareTo()) ✔ Real scenarios to understand outputs better ✨ Level up your Java fundamentals and write smarter, more efficient code! #JavaProgramming #StringHandling #ProgrammingBasics #JavaDevelopers #CodingConcepts #LearnJava #TechEducation #ComputerScience #DeveloperLife #CodeSmart #ProgrammingKnowledge #JavaInternship TAP Academy
To view or add a comment, sign in
-
-
📚 Day 31 – Learning Journey at Tap Academy Today’s session at Tap Academy was focused on understanding the Object class in Java, which is considered the root of the entire Java class hierarchy. One important concept we learned is that every class in Java automatically extends the Object class, even if we don’t explicitly write extends Object. Because of this, all Java objects inherit common behaviors from the Object class, which provides a set of fundamental methods that help manage and interact with objects. 🔹 We explored several important methods available in the Object class, such as: • clone() – used to create a copy of an object. • finalize() – traditionally used for cleanup before garbage collection (though it is rarely used in modern Java). • equals() – used to compare two objects logically rather than comparing their memory addresses. • toString() – used to convert an object into its string representation. Some other Object class methods like wait(), notify(), and notifyAll() are mainly used in multithreading, allowing threads to communicate and coordinate with each other during program execution. 🔹 A major highlight of today’s session was understanding the toString() method in detail. By default, when we print an object in Java, the toString() method returns a fully qualified class name followed by a hexadecimal representation of the object’s hash code, which represents the object's memory reference. This output usually looks something like: Employee@1b6d3586 While this is useful internally, it is not meaningful for developers or users who want to view actual object data. 💡 To solve this, we learned how to override the toString() method inside a class. By overriding it, we can customize what gets printed when the object is displayed. For example, in an Employee POJO class, instead of printing a memory reference, we can display meaningful information such as the employee’s ID, name, or other attributes. This makes debugging easier and improves the readability of our programs. This session helped me understand how core Java classes provide built-in functionality that every object inherits, and how developers can customize that behavior using method overriding. Learning these foundational concepts strengthens my understanding of Object-Oriented Programming principles, which are essential for writing clean, maintainable, and scalable Java applications. Grateful for another productive day of learning and moving one step closer to becoming a better developer. 🚀 #Day31 #Java #ObjectOrientedProgramming #ObjectClass #ToStringMethod #CodingJourney #TapAcademy #LearningEveryday
To view or add a comment, sign in
-
-
Day 12 of My Java Learning Journey at Tech Academy 🚀 Today’s session was a continuation of Strings in Java, and we explored some very important concepts that strengthened my understanding of how Strings work internally. Here are the key takeaways from today’s lecture 👇 🔹 String Concatenation Concatenation is used to combine two strings. There are two ways to perform concatenation: Using the + operator Using the concat() method 🔹 String Memory Allocation String literals are stored in the String Constant Pool. When we create a string using the new keyword, memory is allocated in the Heap area. Since String is an object, it follows object memory allocation concepts. 🔹 String Comparison Methods equals() → Compares content and returns true or false equalsIgnoreCase() → Compares content ignoring case differences These methods do NOT tell which string is greater or smaller. To compare lexicographically, we use: compareTo() → Returns 0 if equal Positive value if first string is greater Negative value if first string is smaller We tested this method using three different cases to understand it clearly. 🔹 Important Concept In Java, length is a method for Strings (length()), not a property. To extract a character from a String, we use the charAt() method — we cannot access it like an array. Every day, I’m gaining deeper clarity on Java fundamentals and improving my problem-solving skills step by step 💻✨ Excited to continue learning! #Java #JavaProgramming #JavaDeveloper #learningJourney #TechAcademy #Programming #CodingLife #SoftwareDevelopment #WomenInTech #LinkedInLearning #DeveloperJourney #ComputerScience #100DaysOfCode #TechCareer #JavaStrings
To view or add a comment, sign in
-
-
Day 32 at TAP Academy | toString() While revisiting some core Java concepts, I realized how many powerful design decisions are hidden in the fundamentals. Here are a few insights worth remembering: 🔹 The final Keyword final can be applied to variables, methods, and classes. • A final variable becomes a constant. • A final method cannot be overridden. • A final class cannot be extended, preventing inheritance. 🔹 Inheritance Constraints in Java Java supports single, multilevel, hierarchical, and hybrid inheritance, but it intentionally disallows multiple and cyclic inheritance. This design choice avoids the classic diamond problem, where ambiguity arises when two parent classes share the same method or property. 🔹 The Object Class – The Root of Everything Every class in Java ultimately inherits from the Object class. It provides 12 methods and a zero-argument constructor, forming the foundation of Java’s object hierarchy. 🔹 Important Methods from Object • toString() – By default returns ClassName@HexHashCode, but developers often override it to display meaningful object data. • clone() – Creates a duplicate object so changes in the copy do not affect the original. • equals() – Frequently overridden to compare object content instead of references. • finalize() – Deprecated since JDK 9 due to unpredictable behavior with garbage collection. 🔹 POJO (Plain Old Java Object) A well-structured POJO typically includes: • Private variables • A zero-argument constructor • A parameterized constructor • Getter and Setter methods 🔹 Is Java Truly Object-Oriented? Interestingly, Java is not purely object-oriented because it includes primitive data types like int and float, which are stored directly rather than as objects. To achieve a more object-centric approach, developers often use wrapper classes and factory methods like valueOf(). 🔹 Performance vs Purity Java keeps primitive types intentionally because creating objects is slower than assigning primitive values. This balance between performance and OOP purity is one of Java’s most pragmatic design choices. Sometimes the most powerful lessons in software engineering come from understanding why a language was designed the way it was. TAP Academy Sharath R Harshit T Sonu Kumar Dinesh K #Java #JavaDeveloper #ObjectOrientedProgramming #OOP #Programming #SoftwareEngineering #Coding #Developers #Tech #ProgrammingLife #LearnToCode #CodeNewbie #CodeDaily #SoftwareDevelopment #BackendDevelopment #TechCommunity #100DaysOfCode #DevelopersLife #JavaProgramming #CodingJourney #ProgrammingTips #CleanCode #SoftwareArchitecture #ComputerScience #TechEducation #Engineering #DevCommunity #CodeLife #ProgrammingLanguages #DeveloperMindset
To view or add a comment, sign in
Explore related topics
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