Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

why string constant pool in java

Answer Posted / shabina

To make Java more memory efficient, the JVM set aside a special area of memory called as "String Constant Pool" or "String Literal Pool".
When the compiler encounters a string literal, it checks the pool to see if an identical strong already exists or not, If not then it creates a new string literal object.
A String object is created out of the string constant pool, even if an equal already exists in the pool. Considering all that avoid new string unless you specially know that you need it.
JVM has a string pool where it keeps at most one object of any string. String literals always refers to an object in the string literal pool.
String objects created with the new string do not refer to objects in the string pool but can be made to using string's intern() method.
the java.lang.string.intern() returns an intended string, that is one that has an entry in the global string pool, then it will be added.
there is a table always maintaining a single reference to each unique object int the string literal pool ever created by an instance of the runtime in order to optimize space.
That means that they always have a reference to string objects in string literal pool. Therefore, the string objects in the string literal pool are not eligible for garbage collection.

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can we write any code after throw statement?

1014


In the below example, what will be the output?

983


Is final static java?

961


What is type parameter in java?

917


What is module in project?

903


What is method reference in java?

1063


Do I need to import java.lang package any time? Why?

1320


What is the numeric promotion?

959


How does multithreading take place on a computer with a single cpu?

958


What happens when a thrown exception is not handled?

1058


What are the three parts of a lambda expression?

955


What is the major difference between linkedlist and arraylist?

974


What is balanced tree in java?

915


What is the use of parseint in java?

978


Which method you will use to create a new file to store some log data. Each time a new log entry is necessary, write string to the file in java ?

1117