Zum Hauptinhalt springen
••
Sichere ProgrammierungYour agent's kill switch was never tested. That is the whole bug.(03.10.2026 um 04:02 Uhr)
•
Sichere ProgrammierungMultilingual Ghost CMS Blog: 5. Making Home Links Language Aware(03.10.2026 um 04:02 Uhr)
•
Sichere ProgrammierungUK Hackathon Statistics(03.10.2026 um 04:03 Uhr)
••
AI & KI NachrichtenThe Rise of AI Co-Architects: Moving Beyond Simple Code Completion(03.10.2026 um 04:04 Uhr)
••
Sichere ProgrammierungHow we check every AI-generated room render before a user sees it(03.10.2026 um 04:05 Uhr)
•
Sichere ProgrammierungHandle partial failures in optional widgets with Promise.allSettled()(03.10.2026 um 04:06 Uhr)
•••
Sichere ProgrammierungYour agent's kill switch was never tested. That is the whole bug.(03.10.2026 um 04:02 Uhr)
•
Sichere ProgrammierungMultilingual Ghost CMS Blog: 5. Making Home Links Language Aware(03.10.2026 um 04:02 Uhr)
•
Sichere ProgrammierungUK Hackathon Statistics(03.10.2026 um 04:03 Uhr)
••
AI & KI NachrichtenThe Rise of AI Co-Architects: Moving Beyond Simple Code Completion(03.10.2026 um 04:04 Uhr)
••
Sichere ProgrammierungHow we check every AI-generated room render before a user sees it(03.10.2026 um 04:05 Uhr)
•
Sichere ProgrammierungHandle partial failures in optional widgets with Promise.allSettled()(03.10.2026 um 04:06 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

Java String Immutability & SCP behavior

In Java, String is a non - primitive data type. String is a sequence of characters / an array of characters. It belongs to the java.lang package and represents…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!

In Java, String is a non - primitive data type.

String is a sequence of characters / an array of characters.

It belongs to the java.lang package and represents sequence of characters.




String name = "Anushka";






String is an object. It is immutable. Stored in special memory called "String Pool".






Why String is Immutable ?



Once created, a String object cannot be changed.




String s = new String("Hello");
s.concat("World");








What happens internally ?




  • "Hello" remains unchanged.

  • " World" is checked in SCP (created if not present).

  • A new object "Hello World" is created in heap.





What is String Constant Pool (SCP) ?



A String Constant Pool is a special memory area inside the Heap where Java stores string literals.

It is used to :




  • Avoid duplicate objects.

  • Save memory.

  • Improve performance.



String s1 = "Java";
String s2 = "Java";





Only ONE Object is created in SCP.

Both s1 and s2 point to the same object.




s1 ─┐
├──► "Java" (SCP)
s2 ─┘










What If We Use new ?






String s3 = new String("Java");






Java is stored in SCP.

A new Object is created in heap.

s3 points to heap object.



So now two objects exist :




  1. SCP object

  2. Heap object






Why SCP exists ?




  • Every string literal would create new object.

  • Huge memory waste.

  • Performance issues.
    SCP makes Java memory efficient.

Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Java String Immutability & SCP behavior

Thematisch verwandte Begriffe: Java, String, Immutability, behavior · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag