what is meant by string pooling?
Answer Posted / ranganathkini
A string pool is a collection of references to String
objects. Strings, even though they are immutable, are still
objects like any other in Java. Objects are created on the
heap and Strings are no exception. So, Strings that are part
of the "String Literal Pool" still live on the heap, but
they have references to them from the String Literal Pool.
When a .java file is compiled into a .class file, any String
literals are noted in a special way, just as all constants
are. When a class is loaded (note that loading happens prior
to initialization), the JVM goes through the code for the
class and looks for String literals. When it finds one, it
checks to see if an equivalent String is already referenced
from the heap. If not, it creates a String instance on the
heap and stores a reference to that object in the constant
table. Once a reference is made to that String object, any
references to that String literal throughout your program
are simply replaced with the reference to the object
referenced from the String Literal Pool.
| Is This Answer Correct ? | 37 Yes | 4 No |
Post New Answer View All Answers
How would you use Bubble Sort to sort the number of elements?
What is the default value of the local variables?
What is compareto () in java?
Why lambda expression is used in java?
Write code to implement bubble sort in java?
Which containers use a flowlayout as their default layout in java programming?
How hashmap increases its size in java?
What is difference between protected and private?
What are the two basic ways in which classes that can be run as threads may be defined?
What are triggers in DB? Explain their types. How do they work?
What is method overriding in java ?
What are abstract classes and anonymous classes?
Explain the hierarchy of java exception classes?
How can we create objects if we make the constructor private ?
What is polymorphism in java? What are the kinds of polymorphism?