• 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

Garbase Collection and Java Litral Pool

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is some object which is free by out Program
e.g
String str= "TestString";
str=null;

But still reffer by the Litral Pool

till Poll hase reffrance to String "TestString"

Doubt 1:
Behavior is JVM's internally so can it eligible for GC because there is no user define reference to this object only JVM's (As pool reference is there) reference is there can it is eligible for GC

Doubt 2: I Believe that JAVA Literal pool manages there own memory for the pooled literal and there is no link between the Pool�s Object Address and Heap Object Address
Reason : when you create String with new operator as String str = �TestString� It will create two object one in Heap Area and one in Pool Area (Reff.: Creating New Strings Ch 6: Kathy Sierra, Page No-410)
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read this:

http://www.javaranch.com/journal/200409/ScjpTipLine-StringsLiterally.html

If you are preparing for SCJP 1.5, remember that Integers, Shorts and such wrappers also using object pooling internally.
 
Pinkal Patel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Anupama,

One thing I know about the SCJP 1.5 All the Wraper class also using pooling like string
But I am more Confuse with there GC behaviewr.

With this artical String GC is beat clear but still have one small question

All Litral Pool Behave like String Litral Pool for GC


For JCP 1.5
 
Pinkal Patel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One more thing and I observed that if the Wrapper class Litral is tacking form the pool if it's value is less than 127
Can any one tell why ?

class Test
{
public static void main(String[] args)
{
test inst_test = new test();
int i1 = 2000;
int i2 = 2000;
int i3 = 2;
int i4 = 2;
Integer Ithree = new Integer(2); // 1
Integer Ifour = new Integer(2); // 2
System.out.println( Ithree == Ifour );
inst_test.method( i3 , i4 ); // Return True
inst_test.method( i1 , i2 ); // Return Flase

}
public void method( Integer i , Integer eye )
{
System.out.println(i == eye );
}
}
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One thing to keep in mind is that the real Sun exam will NOT mix GC in with the concept of a literal pool. So, whenever the exam asks you about objects that might or might not be eligible for the GC, those objects WON'T be of a type that might use a literal pool.

I know a lot of mock exams might mix these two concepts together, but the real exam won't.

hth,

Bert
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
5.1.7 Boxing Conversion:


If the value p being boxed is true, false, a byte, a char in the range \u0000 to \u007f, or an int or short number between -128 and 127, then let r1 and r2 be the results of any two boxing conversions of p. It is always the case that r1 == r2.

 
Pinkal Patel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For Boxing Conversion

int or short number between -128 and 127



Can any one tell Explain
Why int alloved for Boxing upto for this range only
And What is the Range for Boxing for Float, Double and Long
 
Anupama Ponnapalli
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Double does not use caching internally. For long, int, byte, short, character and float do. The range is the for the numeric ones, -128 to 127. For characters, the range is what wise owen quoted.

- Anu
 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is Long and Float pooled.
I think only Byte, Short, Character, Integer are pooled.
 
Pinkal Patel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thing Long is poled
Please Correcte me if I am wrong.
 
reply
    Bookmark Topic Watch Topic
  • New Topic