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
What is thread life cycle in java?
there are N number of matchboxes numbered 1...N.each matchbox contain various number of stick.Two player can alternatevely pick some amount of stick from the higest stick containing box . The player is condidered win if there is no stick after his move.Find the final move so that the move player win. Note:In case the number of stick is equal ,pick the stick from the higest numbered box.
What is class??
What are the parts of methodology?
What is appletviewer?
Explain parallel processing in java8?
what is aggregation in java?
Is it compulsory for a try block to be followed by a catch block in java for exception handling?
What are local variables?
Define Multiprogramming and Multiprocessing in java.
What is the do while loop syntax?
What is dynamic binding(late binding)?
Explain access specifiers?
Why collection doesn’t extend cloneable and serializable interfaces?
Can we have more than one package statement in the source file?