Win a copy of Head First Android this week in the Android 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Is the answer none.

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
String s = "abc";
String s1 = "def";
s=null;
How many objects are eligible for GC.
Is the answer none.
can anybody kindly please answer this question???
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, it is none.
This is same as ur example.
class None {
public static void main(String args[]) {
String a = "abc";
String b = "def";
b =null;
}
}
Now follow the bytecode conversion of this....
class None
{
None()
{
// 0 0:aload_0
// 1 1:invokespecial #5 <Method void Object()>
// 2 4:return
}
public static void main(String args[])
{
String s = "abc";
// 0 0:ldc1 #1 <String "abc">
// 1 2:astore_1
String s1 = "def";
// 2 3:ldc1 #2 <String "def">
// 3 5:astore_2
s1 = null;
// 4 6:aconst_null
// 5 7:astore_2
// 6 8:return
}
}
Can u see any objects created on the heap. No...right. It is only String pool u can see with two string objects..."abc" and "def" which can't be garbage collected.
So, the answer is none. Am I clear with this ?
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My $0.02:



Previously I posted in a different thread here, that for this type of questions of the SCPJ2 exam the <CODE>String</CODE> objects are going to be objects created with the <CODE>new</CODE> keyword.



Let's not loose perspective of what's covered in the exam. The JVM and/or its internal workings are not necessary knowledge. Sure, it would be nice to know everything about EVERYTHING. If you can. If you cannot, it's better to concentrate at least on what's on the test
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic