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


Please Help Members By Posting Answers For Below Questions

What is the difference between a choice and a list?

599


Who found java?

546


Explain different ways of creating a thread. Which one would you prefer and why?

572


Explain about public and private access specifiers?

530


What is 32 bit float?

551






What is scanner in java?

533


What are filterstreams?

603


What are loops in java? What are three types of loops?

545


How many types of memory areas are allocated by JVM in java?

582


What is tree node in java?

524


Difference between operator overloading and function overloading

604


Are functions objects in java?

537


What does the “final” keyword mean in front of a variable? A method? A class?

540


What technique is carried out to find out if a particular string is empty?

563


Is java a digit method?

508