What is the difference between a String literal and a String object?

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.

Diagram: String literals share the pool, new String() creates a new object
String literals share the pool, new String() creates a new object

Key Points

Example

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
    }
}

Difference Between String Literal and String Object

String Literal

String Object

Interview Tip

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?

More Core Java - Level II interview questions

All Core Java - Level II questions