Java Strings: Understanding Objects, Immutable Nature, and Comparison Methods

📘 **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

  • graphical user interface, text, application, chat or text message

To view or add a comment, sign in

Explore content categories