Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

String pool in Java SE 8

 
Greenhorn
Posts: 15
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are string objects in string pool garbage collected?
 
Ranch Hand
Posts: 491
23
Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In short No.please have a look in this →thread.

KindRegards,
Praveen.
 
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe there are some times where Strings in the string pool can be garbage collected -- one being when the string literals are in a class which was loaded by a classloader other than the system classloader, and that class becomes unreferenced. That also requires the classloader to become unreferenced as well, I believe. My description may be wrong in some details (I wouldn't be surprised at all) but I'm pretty sure that's a situation which isn't covered by the OCAJP exam. In fact I suspect the OP's question is also one which wouldn't be asked on the OCAJP either, but somebody who knew more about the exam (of which there are many here) could clarify that.
 
praveen kumaar
Ranch Hand
Posts: 491
23
Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul,you are correct(their can be the situation when String in a constant pool can be garbage collected,String is not an exception! in contrast to other objects).The link i have provided in my previous post contains the information regarding this point.however as far as OCAJP is concerned you are totally correct that these things are beyond the scope of the exam.

Kind Regards,
Praveen.
 
Paul Clapham
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

praveen kumaar wrote:these things are beyond the scope of the exam.



Well, I'm glad to have that confirmed. People spend too much time agonizing over trivia like this.
 
Nayan Das
Greenhorn
Posts: 15
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank u. I feared that it is a must-know topic for OCAJP exam.
 
praveen kumaar
Ranch Hand
Posts: 491
23
Eclipse IDE Firefox Browser Spring VI Editor AngularJS Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Nayan wrote:I feared...

You should not be.
I appreciate that you had ask about things where you feel some confusion and that is a very good habit for a perfect learning.
Though,the topic "Garbage collection" is present there in the OCAJP exam topics but specifically about your question things like classloader,as Paul has already mentioned,is beyond the scope of this exam so you can just stop worrying(or getting feared) about these things.
here→you can have a quick look at the Exam Topics.

Kind regards,
Praveen.
 
Author
Posts: 375
19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its obvious that you get curious with such combination (Garbage collection & String pool), even though it isn't covered in the OCA Java SE 7/8 Programmer I & II exams.

I have created a series of blog posts on String pool (limiting its coverage to the exam):

http://www.ejavaguru.com/blog/

You can also access 15 free sample questions on String pool using this link: http://www.ejavaguru.com/freeresources/strpool/strpoolQ1.html

Thanks.

With much respect,
Mala
 
Nayan Das
Greenhorn
Posts: 15
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Praveen Kumar. My worry is gone now.
And also thank you for your resources Mala Gupta. It was great.
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic