InterviewSolution
| 1. |
What is Java String Pool? |
|
Answer» The developers of Java were WELL aware that programmers would rely heavily on the String data type. As a result, they sought optimization from the BEGINNING. They came up with the idea of storing String literals in the String pool (storage space in the Java heap). As a result, whenever a new object is created, the String pool first checks to see if the object has previously been generated in the pool, and if it has, the same reference is RETURNED to the variable. Otherwise, a new object in the String pool will be created and the reference will be returned. They wanted to use SHARING to reduce the size of the TEMPORARY String object. To make sharing easier, an immutable class is required. It is not possible to share mutable structures with two unknown parties. As a result, immutable Java Strings aid in the implementation of the String Pool concept. |
|