Answer Posted / loknathreddy
String constant pool is a separate block of memory where
String object are held by JVM.
If a String object is created directly by using assignment
operator(=) as
String s1="Hello";
then it is stored in String Constant pool.
One of important characteristic of String constant pool is
that it doesn’t create same String object if there is
already in the String constant pool.
String s1 = “Hello”;
String s2 = “Hello”;
For above two String objects, JVM creates only one object
in the String constant pool and for the second string
reference variable (s2) will created, it points the string
object which is created for s1. In this case, (s1 == s2) is
true.
but when we use new operator to create object then this
object will store in heap memory.. be carefull on this.
| Is This Answer Correct ? | 26 Yes | 2 No |
Post New Answer View All Answers
Can finally block be used without a catch?
What is unicode used for?
What is a copy constructor in java?
What is the purpose of the System class?
If you are given the name of the function at run time how will you invoke the function?
What is java util concurrentmodificationexception?
Can a constructor be made final?
Which object oriented concept is achieved by using overloading and overriding?
Is class forname reflection?
I want to re-reach and use an object once it has been garbage collected. How it's possible?
What are the main uses of the super keyword?
Why doesn't the java library use a randomized version of quicksort?
Difference between character constant and string constant in java ?
Define jre i.e. Java runtime environment?
What does super keyword do?