Now I know this question is asked a lot of times, and has been answered many times, but still someone new to Java will find the explanation tough to understand. So what I have understood from these question is as follows
String a = "hi";
The above statement first checks whether the string is present in string pool. If not, it adds it in the pool and a reference of it is created in the pool. Basically the object is made in permanent generation area and string pool is used to have a reference of it.
However, with
String a = new String("hello");
In this case, it creates two object. One in permanent generation area, and one in the normal heap memory. The a
contains a reference to the heap memory object.
Now my question is whether this concept is right or not. Does string pool is references or a pool of actual strings and whether the concept of permanent generation area here I understood is right or not? If wrong please explain in layman's language. Please don't make it duplicate, as I already know this has been answered a lot of times. None was in layman's language and easy to understand. Are two objects actually made? If yes, then how, and if no, then why? It would be really helpful.