Pools in JAVA.
In this article series, I wish to share pools in Java. like String.Integer, byte, short, charater and boolean pools. There are no pools for float and double data types.
And the motivation for this article series was this topics were asked during the interview for interns, even at the ASE level. So I hope to share my findings and what I learn from them during the process.
This article is for the well-known frequently asked questions and keywords for an interview called the String pool or the String constant pool.
You already know String is a class or non primitive data type in Java, and it has a pool called the String pool inside the Heap memory, and it is inside the JVM’s runtime Data Area. I have an idea for the JVM architecture series. For now, I think you already know about JVM, Heaps and architecture.
So, what is Pool? In simple word is reusble cache for storing frequently used objects, which can be used for performance and memory efficiency.
You already heard about the thread pool, also. This is a different story.
Get Heshan Umayanga’s stories in your inbox
Join Medium for free to get updates from this writer.
As you know, String pool is inside the heap memory section, and it stores frequently used strings in java program, basically variable etc.
This is a special memory area in the JVM that stores unique String Objects. Using these pool values, we don't need to create objects for existing values. String values are immutable, so they are used for immutable values for strings.
Let’s take an example and make it clear.
Normally, string objects are created in Heap memory inside the string pool, but if we use the new keyword for creating string, it will be created inside heap memory outside the string pool.
This ensures immutability, and we can usethe same object reference for this example “Hello” anywhere in our code. You already know the String class is both an immutable and thread-safe class. It is like a use tank, a shared cache for frequently accessed and changing objects.
This is enough for the String pool in Java. The next article will be Integer pool.
Reference-Java Documentation.









