java - How JVM allocates memory to static String variables? -


since jvm allocates memory static variable type in method area. when comes static string type refer heap area method area or provides memory in method area there itself. if refer heap area string have same behaviour(for below example)?

example:

static string s1 = new string("aman"); static string s2 = "aman"; 

you conflating variables s1 , s2 objects refer to.

the objects in heap. literal "aman" in string pool subdivision of heap.

the variables, being static, in class.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -