A String literal and a String object both represent text data in Java, but they differ in how they are created, stored in memory, and managed by the JVM. String literals are stored in the String Pool for reuse, whereas String objects created with the new keyword are allocated in heap memory as separate objects.
If two variables are assigned the literal "Java", both point to the same object in the String Pool. However, if a String is created using new String("Java"), a separate object is created in heap memory.
public class Demo {
public static void main(String[] args) {
String str1 = "Java";
String str2 = "Java";
String str3 = new String("Java");
System.out.println(str1 == str2); // true
System.out.println(str1 == str3); // false
System.out.println(str1.equals(str3)); // true
}
}A concise interview answer is
A String literal is stored in the String Pool and can be shared by multiple references, improving memory efficiency. A String object created using new String() is stored separately in heap memory and creates a new object every time, even if the same value already exists in the String Pool.
Last updated: 11 November 2026
Previous question: Give a scenario where StringBuffer is better than String.
Next question: Why is String immutable?