In a previous article Why String is Immutable and Final in Java , I have discussed why String is immutable in nature and advantages and disadvantages String's immutability gives us. I have also discussed that, all String literals are cached into a special memory area called String Constant Pool and how String's immutability made String constant pool possible. But the question arises why do Java required a separate constant pool to store Strings, What's the reason, Why strings are not stored in the normal heap memory like other objects do and in this article, I will try to answer these questions. String Interning Well, we know String is the most popular type present in Java and almost all Java programs use it. In fact, I have not seen a single Java program which is written without using String. In general, a normal Java business application deals with thousands of string objects, lots of them have same value associated and lots of them are mid operations string means they a
Java By Source
Naresh Joshi's blog for Java Language, Spring, Hibernate, Struts, Web Services, Micro Services, Design Patterns, Multi-threading, Collection XML, SQL.