Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please Let Me Know The differences Between These Two Object Creation.. In the First Case object will be created in Heap Area But In second Case Object Will Be created in String Constant Pool (scp) Area ..Is It The Answer or something else.
Posted
Comments
Sergey Alexandrovich Kryukov 26-Feb-14 2:35am    
First case won't even compile. Was it so difficult to check it up, before asking a question? :-)
—SA

1 solution

Not true at all. This type is designed in much wiser way: there is no such constructor. These constructors do not exist: string(); string(string); the are simply never needed and having them would be even harmful.

You mentioned the pool. It also does not work as you thought, and it is called intern pool. Please read about interning; it is very interesting:
http://en.wikipedia.org/wiki/String_intern_pool[^],
http://msdn.microsoft.com/en-us/library/system.string.intern(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.string.isinterned(v=vs.110).aspx[^].

—SA
 
Share this answer
 
Comments
Maciej Los 26-Feb-14 3:02am    
+5
Sergey Alexandrovich Kryukov 26-Feb-14 9:35am    
Thank you, Maciej.
—SA
RAVI _4378 26-Feb-14 3:17am    
Plz tell me the reason why This Code will Not Compile

package mypack;

public class Test {

public static void main(String args[])
{

String s=new String ();
String s1="abc";

System.out.println(s1);
System.out.println(s);

}

}


o/p
abc

This Compiling As well As o/p
Sergey Alexandrovich Kryukov 26-Feb-14 9:37am    
"String does not contain a constructor that takes 0 arguments"
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900