Vaclav Burda wrote:What is in literal pool at this monent? Is empty or have poiner to the heap, where is instance of String?
It is neither empty nor referring to the heap. Look carefully at the instantiation line. For the constructor of the String, you passed a String literal value, "Hello", which will be pooled. But the variable str1 is still referring to the String object in the heap.
Typically the String pool can never empty. It may contain *many* of string values including strings created by the class loader process.
String pooling technology is designed to reuse a same String value again and again without creating new objects in heap. In your second program, there are two statements. First statement pools the string value "someString" in the pool. So, no need to pool the same string *again*, because it is existing in the String pool, and it can be reused from the pool. For that reason, the argument you passed to the constructor at the second statement will NOT be pooled. Instead of that it gets the previously pooled value from the pool, and it is used as the argument to construct the NEW string object on the heap.