🌟 Day 15 – Java Learning at TAP Academy: Strings Uncovered! 🌟 Today, I dove deep into Java Strings – one of the most subtle yet crucial topics in Java programming. Here’s a quick recap of what I learned: 💡 What’s a String? A sequence of characters in double quotes, but remember – in Java, Strings are objects, not primitives. Immutable by default! 🛠 Creating Strings 1️⃣ new String("Java") → Heap memory, duplicates allowed 2️⃣ "Java" → String Constant Pool, duplicates NOT allowed 3️⃣ From char[] → Heap memory, duplicates allowed 🧠 Memory Insights "Java" == "Java" → true (same pool object) new String("Java") == new String("Java") → false (different heap objects) Always use .equals() for value comparison 🔍 Comparing Strings == → reference comparison .equals() → case-sensitive value comparison .equalsIgnoreCase() → ignore case .compareTo() → lexicographical order ➕ Concatenation Rules + with literals → Pool (reuse) + with references → Heap .concat() → Always Heap (immutable strings, original unchanged) 🎯 Key Takeaways Pool = no duplicates, Heap = duplicates allowed Avoid == for values Concatenation behaves differently based on literals vs variables 💻 Practice Tip: Test scenarios like "A" vs new String("A"), + with literals & references to really internalize memory behavior. Learning Java is like exploring a layered maze – every day brings new insights! 🚀 #Java #StringInJava #TAPAcademy #Day15 #ProgrammingJourney #CodingTips #ImmutableStrings #JavaLearning
Java Strings: Immutable Objects and Memory Insights
More Relevant Posts
-
📘 **Day 17 – Java Learning Journey** Today I explored one of the most important concepts in Java: **Strings**. Here are some key points I learned while practicing and analyzing my notes: 🔹 **What is a String?** A String is a sequence (collection) of characters enclosed within double quotes. Example: `"Java"` 🔹 **Strings are Objects in Java** Unlike primitive data types, Strings are objects created from the `String` class. 🔹 **Immutable Nature of Strings** Strings in Java are **immutable**, meaning once a String object is created, its value cannot be changed. 🔹 **Different Ways to Create Strings** 1️⃣ `String s = "Java";` → Stored in the **String Constant Pool** 2️⃣ `String s = new String("Java");` → Stored in **Heap Memory** 3️⃣ Using character arrays 🔹 **String Comparison Methods** ✔ `==` → Compares **references (memory location)** ✔ `.equals()` → Compares **values/content** ✔ `.compareTo()` → Compares **character by character** ✔ `.equalsIgnoreCase()` → Compares **ignoring case differences** 🔹 **String Concatenation** Strings can be combined using: • `+` operator • `concat()` method Understanding concepts like **String Constant Pool, Heap Memory, and Reference Comparison** helped me clearly see how Java manages memory. Every day I’m learning something new and strengthening my Java fundamentals step by step. 🚀 #Java #Programming #LearningJourney #JavaDeveloper #ComputerScience #Coding TAP Academy
To view or add a comment, sign in
-
-
🚀 Starting My Java Learning Journey – Day 6 🔹 Topic: Loops in Java Loops in Java are used to execute a block of code repeatedly until a certain condition is met. Java mainly provides three types of loops: 1️⃣ for Loop Used when the number of iterations is known. Example: public class Main { public static void main(String[] args) { for(int i = 1; i <= 5; i++) { System.out.println(i); } } } 2️⃣ while Loop Used when the number of iterations is not known beforehand. Example: public class Main { public static void main(String[] args) { int i = 1; while(i <= 5) { System.out.println(i); i++; } } } 3️⃣ do-while Loop The do-while loop executes the code at least once even if the condition is false. Example: public class Main { public static void main(String[] args) { int i = 1; do { System.out.println(i); i++; } while(i <= 5); } } 💡 Key Point: Loops help automate repetitive tasks and make programs more efficient. #Java #JavaLearning #Programming #BackendDevelopment #CodingJourney #JavaLoops
To view or add a comment, sign in
-
DAY 29: CORE JAVA 🔗 Constructor Chaining in Java using "super()" (Inheritance) While learning Java OOP concepts, one interesting topic I explored is Constructor Chaining in Inheritance. 📌 What is Constructor Chaining? Constructor chaining is the process of calling one constructor from another constructor. In inheritance, a child class constructor calls the parent class constructor using "super()". This ensures that the parent class variables are initialized before the child class variables. ⚙️ Key Points to Remember • "super()" is used to call the parent class constructor. • It must be the first statement inside the child constructor. • If we don’t explicitly write "super()", Java automatically calls the parent class default constructor. • This mechanism ensures proper initialization of objects in inheritance hierarchy. 💡 Example Scenario Parent Class: class Test1 { int x = 100; int y = 200; } Child Class: class Test2 extends Test1 { int a = 300; int b = 400; } When an object of "Test2" is created, Java first calls the parent constructor, initializes "x" and "y", and then initializes "a" and "b". 📊 Execution Flow 1️⃣ Object of child class is created 2️⃣ Child constructor calls "super()" 3️⃣ Parent constructor executes first 4️⃣ Control returns to child constructor This concept is very important for understanding object initialization, inheritance hierarchy, and memory allocation in Java. 🚀 Learning these small internal mechanisms of Java helps build a strong foundation in Object-Oriented Programming. TAP Academy #Java #OOP #ConstructorChaining #Inheritance #JavaProgramming #SoftwareDevelopment #CodingJourney
To view or add a comment, sign in
-
-
🚀 Learning Update: Java — Method Overloading, Type Promotion, CLI Args & Encapsulation (OOP) In today’s live Java session, I revised some core concepts that are frequently tested in interviews and also form the foundation for Object-Oriented Programming. ✅ Key Learnings: 🔹 Method Overloading (Compiler-based / Compile-time Polymorphism) Multiple methods with the same name in the same class Java Compiler checks in order: Method Name Number of Parameters Type of Parameters If all 3 are the same → Duplicate method error If exact match isn’t found → Java tries Type Promotion (closest match) If more than one method becomes eligible after promotion → Ambiguity error 🔹 Can we overload main()? ✅ Yes, main method can be overloaded But JVM always starts execution from: public static void main(String[] args) Other overloaded main() methods can be called manually using an object/reference. 🔹 Command Line Arguments (CLI) Inputs passed in terminal get stored in String[] args Args are always Strings (even numbers) + with args performs concatenation, not addition (unless you convert manually) 🔹 OOP Introduction + Encapsulation (1st Pillar) Encapsulation = Protecting the most important data + giving controlled access Use private variables for security Provide controlled access using: ✅ Setter → set/update data (usually void) ✅ Getter → get/return data (has return type) Add validations inside setter (ex: prevent negative bank balance) 📌 Realization: These concepts are not just theory — they directly relate to writing secure, industry-ready code. #Java #OOP #Encapsulation #MethodOverloading #CommandLineArguments #LearningUpdate #FullStackDevelopment #PlacementPreparation #TapAcademy #SoftwareDevelopment TAP Academy
To view or add a comment, sign in
-
-
Today’s Learning Update ✅ (Core Java — Strings) In today’s session, I learned one of the most important foundational topics in Java: Strings — how they are created, stored in memory, compared, and concatenated. 📌 Key Learnings: ✅ What is a String in Java? A String is a sequence/collection of characters enclosed in double quotes (" "). Also, Strings are objects in Java. ✅ Types of Strings Immutable String → cannot be changed (created using String class) Mutable String → can be changed (covered briefly; will be explored further) ✅ Ways to create an Immutable String Using new keyword Without new (String literal) Using char[] array and converting to String ✅ String Memory Concept (Very Important!) Java allocates String memory in two places inside Heap: String Constant Pool (SCP) → created without new, duplicates not allowed Heap Area → created with new, duplicates allowed ✅ Comparing Strings == → compares references (address) .equals() → compares values .equalsIgnoreCase() → compares values ignoring case .compareTo() → compares character by character (covered for later) ✅ String Concatenation Using + operator Using .concat() method ⚡ Important insight: + with two string literals → goes to SCP + with references → goes to Heap .concat() → always creates result in Heap 🧠 This session made me understand why String fundamentals are asked frequently in interviews, especially around == vs equals() and SCP vs Heap behavior. #Java #CoreJava #Strings #Programming #DSA #Learning #InterviewPreparation #SoftwareDevelopment #Coding TAP Academy
To view or add a comment, sign in
-
-
Day 13 – Exploring Strings in Java | My Learning Journey Today I continued my journey of learning Java and explored more concepts related to Strings. Strings are one of the most commonly used data types in programming because they help us work with text data effectively. 🔹 1. String Concatenation in Java String concatenation means combining two or more strings into a single string. In Java, this is commonly done using the + operator or the concat() method. Example: String firstName = "Hello"; String secondName = "World"; System.out.println(firstName + " " + secondName); Output: Hello World 🔹 2. Built-in Methods in String Java provides many built-in methods in the String class that help us perform operations easily. Some commonly used methods include: length() – Returns the length of a string charAt() – Returns the character at a specific index toUpperCase() – Converts string to uppercase toLowerCase() – Converts string to lowercase contains() – Checks if a string contains a specific value substring() – Extracts part of a string Example: String text = "Java Programming"; System.out.println(text.toUpperCase()); 🔹 3. StringTokenizer StringTokenizer is used to split a string into multiple tokens based on a delimiter like space, comma, or any other character. Example: import java.util.StringTokenizer; String str = "Welcome to Java"; StringTokenizer st = new StringTokenizer(str); while(st.hasMoreTokens()){ System.out.println(st.nextToken()); } Output: Welcome to Java Understanding string concatenation, built-in string methods, and String Tokenizer helps in handling and manipulating text data efficiently in Java applications. 💡 Every day I’m learning something new and improving my programming skills step by step. #Java #LearningJava #JavaProgramming #CodingJourney #Strings #DaysOfCode #DeveloperJourney
To view or add a comment, sign in
-
-
🚀 Learning Java OOP Understanding Object Class in Java As part of my learning journey in Java Object Oriented Programming, I explored one of the most fundamental concepts: the Object Class. 🔹 In Java, every class directly or indirectly inherits from the Object class 🔹 It acts as the root of the entire class hierarchy 🔹 Because of this, every object in Java automatically gets some default behaviors and methods 📌 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 copy of an object ✅ wait(), notify(), notifyAll() → Used in multithreading communication ⚠️ finalize() → Deprecated method (no longer recommended) 💡 Key Insight When we print an object reference using System.out.println(object), Java internally calls the toString() method. This is why overriding toString() helps display object data in a more meaningful and readable format. 📊 Did you know? The Object class contains 12 methods and 1 constructor, making it the ultimate parent of all Java classes. I’m excited to continue exploring deeper concepts in Java and OOP! #SharathR #TapAcademy #Java #OOP #ObjectClass #Programming #JavaDeveloper #SoftwareDevelopment #LearningJourney
To view or add a comment, sign in
-
-
🚀 Day 15 | Core Java Learning Journey 📌 Topic: Abstraction in Java – Abstract Class Today, I explored Abstract Classes, another important way to achieve Abstraction in Java. 🔹 What is an Abstract Class? ✔️ A class declared with the abstract keyword ✔️ Cannot be instantiated (no objects directly) ✔️ Can contain abstract & concrete methods ✔️ Used as a base/template for other classes 🔹 Key Rules of Abstract Class ✔️ May contain abstract methods (no body) ✔️ May contain normal methods (with body) ✔️ Can have constructors & variables ✔️ Child class must implement abstract methods ✔️ Supports single inheritance only 🔹 Example: abstract class Animal { abstract void sound(); // abstract method void eat() { // concrete method System.out.println("Eating..."); } } class Dog extends Animal { void sound() { System.out.println("Barking..."); } } public class Main { public static void main(String[] args) { Dog d = new Dog(); d.sound(); d.eat(); } } 🔹 Why Use Abstract Classes? ✔️ To provide common base functionality ✔️ To enforce method implementation ✔️ To achieve partial abstraction ✔️ To share code among related classes 📌 Abstract Class vs Interface (Quick Insight) ✔️ Abstract Class → Can have method bodies & state ✔️ Interface → Only method declarations (conceptually) ✔️ Abstract Class → Uses extends ✔️ Interface → Uses implements 📌 Key Takeaway ✔️ Abstract Class = Blueprint + Implementation ✔️ Cannot create objects directly ✔️ Helps build structured class hierarchy Special thanks to Vaibhav Barde Sir for simplifying Abstraction concepts 💻 #CoreJava #JavaLearning #OOP #Abstraction #AbstractClass #JavaDeveloper #LearningJourney
To view or add a comment, sign in
-
-
Day 14 – Learning Java Full Stack Today’s let's learn about the most interesting concepts in Java — Recursion. Recursion happens when a method calls itself. A method (or function) is said to be recursive if it solves a problem by calling itself again and again until a stopping condition is met. 🔹 Two Scenarios in Recursion 1️⃣ Indirect Recursion In this scenario, one method calls another method, and that method calls the first method back. Example flow: disp() → test() → disp() → test() → ... This creates a cycle between methods. 2️⃣ Direct Recursion In this scenario, a method calls itself directly. Example idea: display() → display() → display() → ... Important Note- If recursion is not properly controlled using a condition, it will lead to Stack Overflow Error. So every recursive method must have: ✔ A base condition (stopping condition) ✔ A recursive call 🔹 Controlled Recursion Example (Concept) A method prints a value and calls itself with an updated value until a condition becomes false. Example idea: display(1) if value <= 5 → increment → call display again This ensures recursion stops at the right time. Key Takeaway: Recursion is powerful, but it must be used carefully. Without a proper base condition, it can crash the program. Understanding recursion improves logical thinking and prepares you for advanced data structures like trees and graphs. #Java #JavaFullStack #Recursion #ProgrammingBasics #LearningInPublic #CoreJava
To view or add a comment, sign in
-
-
DAY 22 : CORE JAVA 🔹 Understanding "this" Keyword vs "this()" Method in Java 🔹 While learning Java, one common confusion is the difference between the "this" keyword and the "this()" method. Let’s break it down in a simple way 👇 ✅ 1️⃣ "this" Keyword The "this" keyword refers to the current object of a class. 📌 It is mainly used to: - Resolve variable shadowing (when instance variables and constructor/method parameters have the same name). - Refer to current class instance variables. - Call current class methods. 💡 Example: class Student { String name; Student(String name) { this.name = name; // Resolves shadowing problem } } Here, "this.name" refers to the instance variable, while "name" refers to the constructor parameter. 👉 "this" can be used in any line of a constructor or method. ✅ 2️⃣ "this()" Method The "this()" method is used for constructor chaining — calling one constructor from another constructor within the same class. 📌 Key Rule: - "this()" must always be the first statement inside a constructor. - It cannot be used inside regular methods. 💡 Example: class Student { String name; int age; Student() { this("Unknown", 0); // Calls parameterized constructor } Student(String name, int age) { this.name = name; this.age = age; } } 👉 This improves code reusability and avoids duplication. 🔎 Key Differences "this" Keyword| "this()" Method Refers to current object| Calls another constructor Used to resolve shadowing| Used for constructor chaining Can be used in methods & constructors| Used only inside constructors Can appear anywhere in method/constructor| Must be first statement in constructor 💬 Mastering small concepts like "this" and "this()" builds a strong foundation in Object-Oriented Programming. Keep learning. Keep building. 🚀 TAP Academy #Java #OOP #Programming #SoftwareDevelopment #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