Recall & Review
beginner Click to reveal answer
What does it mean that a String is immutable in Java?
It means once a String object is created, its content cannot be changed. Any modification creates a new String object.
intermediate Click to reveal answer
Why are Strings designed to be immutable in Java?
Immutability helps with security, thread safety, and performance optimizations like string pooling.
beginner Click to reveal answer
What happens when you try to change a String using methods like concat() or replace()?
These methods do not change the original String. Instead, they return a new String with the changes.
intermediate Click to reveal answer
How does String immutability affect memory usage in Java?
Because Strings are immutable, Java can safely share String objects in the string pool, reducing memory use.
beginner Click to reveal answer
Can you modify the characters inside a String object directly in Java?
No, you cannot change characters inside a String directly because Strings are immutable.
What happens when you call the replace() method on a String in Java?
✗ Incorrect
Since Strings are immutable, replace() returns a new String with changes, leaving the original unchanged.
Why is String immutability important for thread safety?
✗ Incorrect
Immutable objects cannot be changed, so multiple threads can safely use the same String without conflicts.
Which of these is true about Java Strings?
✗ Incorrect
All Java String objects are immutable regardless of how they are declared.
What is the benefit of the String pool in Java?
✗ Incorrect
The String pool stores unique String objects to avoid duplicates and save memory.
If you want to change characters in a sequence of text efficiently, what should you use instead of String?
✗ Incorrect
StringBuilder and StringBuffer are mutable and allow efficient text modifications.
Explain what String immutability means in Java and why it is useful.
Think about what happens when you try to change a String.
You got /3 concepts.
Describe how Java uses the String pool and how immutability makes it possible.
Consider why sharing mutable objects would be risky.
You got /3 concepts.
