Exams Knowledge Hub

MCQs for Competitive Exams, School & College Exams

Module: | Classes, Objects, OOPs & Inheritance

Q37: Consider the following statements regarding String initialization and memory allocation:

1. Creating a String utilizing double quotes (a String literal) commands the JVM to first search the String Constant Pool to aggressively reuse an identical existing sequence before allocating new memory.
2. Instantiating a String utilizing the 'new' keyword forcibly bypasses the String Pool entirely, creating a brand new, independent object strictly in the general Heap memory space.
3. The String Constant Pool is historically located entirely within the Stack memory layer to ensure ultra-fast string comparison and validation operations during application execution.

Which of the above statements is/are correct?
A
Only 1 and 2
B
Only 1 and 3
C
Only 2 and 3
D
1, 2, and 3
✅ Correct Answer: A
🎯 Quick Answer:
The correct combination is 1 and 2. Statement 3 is incorrect because the String Constant Pool is physically located within the general Heap memory (prior to Java 7, it was in the PermGen space, which was still outside the Stack). Stack memory only holds primitive locals and reference pointers, never actual String objects.
Concept Definition: The String Constant Pool (intern pool) is a specialized memory cache utilized by the JVM to aggressively minimize memory overhead by preventing the creation of duplicate String objects containing identical text.
Structural Breakdown: Syntax 'String s = "Hello";' utilizes the pool.
Syntax 'String s = new String("Hello");' creates two objects if "Hello" is not pooled (one in the pool, one in the general Heap), but the reference variable strictly points to the independent Heap object.
Historical/Related Context: Strings routinely comprise up to 40% of the memory footprint of massive enterprise Java applications (e.g., XML parsing, database query results). The creation of the String Pool was a critical architectural decision by Sun Microsystems to drastically slash memory consumption in sprawling network servers.
Causal Reasoning: The 'new' keyword explicitly serves as an override command to the JVM.
By typing 'new', the developer actively demands the creation of an entirely fresh memory allocation.
To honor the developer's explicit command, the JVM must bypass the Pool's optimization logic and forge an independent Heap object.