Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constant String Pool

 
Pavan Shahi
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
When we create a string literal like

String str=�SCJP�;

Then what happen actually is a String Object is created on Constant String Pool or Object is created on heap as any other object and Constant String Pool contain only reference of that object crrated.

Thanks
Pavan
 
wise owen
Ranch Hand
Posts: 2023
 
faisal usmani
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Pavan ,

Welcome to Javaranch, regarding your question the literal is on heap and reference varibale to the literal is in String Pool .


Hope i answered you

-faisal
[ May 09, 2006: Message edited by: faisal usmani ]
 
Shaliey Gowtham
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objects are always created on the heap.
The reference to the literal Objects are stored in the String pool.
And the reference variable str also contains the same value as the reference value in the String pool.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic