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

How do you add spaces in java?

510


What is type inference in java8?

573


Should a main method be compulsorily declared in all java classes?

534


can rmi and corba based applications interact ?

664


Can inner class have constructor?

545






What exceptions occur during serialization?

602


Explain different states of a thread in java?

581


What are the major drawbacks of external iteration?

572


what is anonymous class in java?

542


What are the main differences between notify and notifyAll in Java?

581


What are the differences between string, stringbuffer and stringbuilder?

518


take an array with -ve and +ve value both.find out the nearest value of 0(zero).if two values are same like(-2 and +2)then extract +2 is nearest of 0(zero).

1529


Why do we need singleton class?

547


What are inbuilt functions?

568


What is the difference between inner class and nested class?

548