0% found this document useful (0 votes)
5 views17 pages

Understanding Strings in Java

The document provides an overview of the String class in Java, explaining that strings are objects representing sequences of characters. It outlines seven stages of understanding strings, including creation methods, memory storage, immutability, and case sensitivity. Key points include the distinction between string literals and objects created with the 'new' keyword, as well as the concept of the String constant pool (SCP).

Uploaded by

abhikale007123
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views17 pages

Understanding Strings in Java

The document provides an overview of the String class in Java, explaining that strings are objects representing sequences of characters. It outlines seven stages of understanding strings, including creation methods, memory storage, immutability, and case sensitivity. Key points include the distinction between string literals and objects created with the 'new' keyword, as well as the concept of the String constant pool (SCP).

Uploaded by

abhikale007123
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

String in

JAVA
Presented By :
Sakshi Jadhav
Introduction
▪ Generally, a string is a sequence of
character. But in java, String is an
object that represents sequence of
characters.
▪ String class is used to create string
object.
▪ We will study 7 stages to understand
the String class briefly

11/21/2025 Annual Review 2


Stage 1 –

Creation of String
• We can create String object by two ways:
1. By using new keyword
String str = new String(“Hello”);
2. By String literal
String str= “Hello”;
When we create object without new keyword, we call it literal

11/21/2025 Annual Review 4


Stage 2 –

How String literals


are Stored in Java
Memory
• When we create a string object without new keyword then a small
amount of memory is created in RAM called String constant pool
• SCP is only one in RAM
• SCP has drawback that its only one so it can be filled with literals.

11/21/2025 Annual Review 6


Stage 3 –

Initializing the
same char sequence
using string literals
• Every time you create a string literal then JVM checks if the value
is already present. If the value is already present then the reference
variable points to that value without putting again that value in
SCP.
• If the string not found then new instance is created &placed in pool.

11/21/2025 Annual Review 8


Stage 4 –

Updation in string
values
• In SCP its possible that all reference variables are pointing to single
literal or no one pointing to any literal still it is present in SCP.
• If we update the value of string object then the reference variable is
going to point the value present in SCP without deleting the value.

11/21/2025 Annual Review 10


Stage 5 –

String Immutable
• Once the value goes inside the SCP we cannot change it this
property is called as immutability.
• Strings is Immutable in java.

11/21/2025 Annual Review 12


Stage 6 –

Case – sensitive
• String is case - sensitive
• “Hello” and “hello” both considered as two different strings.

11/21/2025 Annual Review 14


Stage 7 –

How String are


Stored in Java
Heap Memory
• When we create a string object by using new keyword the object is
created in heap memory, the reference variable points to heap
memory & one copy of value is stored in SCP.

11/21/2025 Annual Review 16


Thank You !!

You might also like