• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String literal pool

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am a newbie to Java. I know that whenever the jvm encounters a string literal in a program, it checks the string literal pool if the same string literal object exists in the string pool. But since string pool contains only a reference to the string object in the heap, how will it identify if the same string object already exists?

It would help me to resolve my doubt to a great extent if anyone can explain me in detail the process of How a string is checked in string pool for existing string object with the new literal encountered

Thank you
sdwork
 
Monish Kaushal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read the article from the link http://www.javaranch.com/journal/200409/Journal200409.jsp#a1 in the forum. But I would like to know the exact process of how the JVM compares the string literal to see if there is a string object in the heap with the same literal value as the one to be created.
 
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess the JVM specification would be a good place to start: http://java.sun.com/docs/books/jvms/first_edition/html/VMSpecTOC.doc.html
Specifically the section describing constant pool resolution.

By the way, welcome to JavaRanch

 
Monish Kaushal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jelle Klap, Thanks a lot for the reply. Link to JVM specs cleared not only the doubt on String pool, but also lot of other doibts on how JVM functions!

Thank you once again

Success Designs
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Success Designs wrote:Hi Jelle Klap, Thanks a lot for the reply. Link to JVM specs cleared not only the doubt on String pool, but also lot of other doibts on how JVM functions!

Thank you once again

Success Designs



No worries. Though I mistakenly placed a link to the first edition of the JVM spec.
The second edition can be found here: http://java.sun.com/docs/books/jvms/second_edition/html/VMSpecTOC.doc.html
 
reply
    Bookmark Topic Watch Topic
  • New Topic