String name = "Tom" for the first time creates a string literal in memory.
Subsequent use of the same literal will cause the creation of a new link in the same place.
String cat = "Tom" will use the same string, the addresses are the same.
String name = new String("Jerry"); creates a new object in memory.
If you make String mouse = new String("Jerry"); - create another object in memory. Addresses are different, i.e. the string "jerry" is stored twice.
There is more subtlety. Comparison with "==" verifies the identity of addresses, and the String.equals method performs a comparison of the content. Therefore, name==mouse returns false - the addresses are different.
This example:
public void foo(){ new String("Моя строка"); }
doesn't make much sense. A link to a new object must be assigned somewhere. In languages without garbage collection, such code will lead to memory leaks; in Java, a hanging object must be disposed of. For the rest of the examples, the above remains valid.
I do not really understand what a link is.
You have Kolyan on your phone and its number.
His mom has a "son" and his number.
At the head of the phone recorded "sysadmin" and his number.
A friend recorded "eared zaya" and his number.
Kolyan is one, and there may be several references to it.
Kolyan resigned, the chief hired a new sysadmin. The link in his phone has become invalid (in Java, the collector may follow this, but in this context it is irrelevant).
He hired a new sysadm = ("Петин номер"); and his link now points to a new object.
And yours has not changed, he is still Kolyan.