
π Day 30 of My Automation Journey β Java Strings (Package, Memory, Limitations & Real-Time Usage) - part 2
When learning Java, most people understand what a String is , but very few understand: π Which package it belongs to π Why it has limitations π How Java overcomes those limitations π Memory behaviour of Strings π Real-time usage in projects Letβs break everything down in a simple and practical way π π¦ 1. Which Package Does String Belong To? π The String class belongs to: java . lang . String Important Points: java.lang package is imported by default So you donβt need to write: import java.lang.String ; π Thatβs why we directly use: String name = "Bala" ; π§± 2. What Type of Class is String? π String is a: Final class β (cannot be inherited) Immutable class π (cannot be changed) public final class String Why final? π For security and consistency β οΈ 3. Demerits of String in Java Even though String is powerful, it has some drawbacks: β 1. Immutable (Cannot Modify) String s = "Hello" ; s = s + " World" ; π Creates new object every time β 2. Memory Consumption Too many modifications β too man
Continue reading on Dev.to
Opens in a new tab



