q1)1.0/0.0 can produce Double.POSITIVE_INFINITY what happens with -1.0/0.0 1.0/-0.0 q2)String literels will never garbage collected. true/false anyone seeing the questien, plz spent only a very little time with it wishing u a nice refreshment..
1) The compiler can tell the difference between negative 0.0 and postive 0.0 (please refer to the JLS and api for more details). Both -1.0/0.0 and 1.0/0.0 produce Double.NEGATIVE_INFINITY 2)String literal are not objects so they can't be garbage collected. (However, the String objects created from the String literals may be gc)
String literal are not objects so they can't be garbage collected
It is indeed true that they are not gced, but what makes you think that they are not object??? Explain please. You can use a String literal exactly the same way you use a normal String, you can invoke the same methods on them, so what makes you think they are not objects ???
Originally posted by Seany Iris: Who can explain "String literels will never garbage collected. " to me?
A string literal is the characters between double quotes in a java program, like "hello world." When you create a string in java, you can do one of two things... String str1 = "Hello World";//set str1 to point to this string literal object already created for you when the program starts. or String str2 = new String("Hello World"); //str2 now references a brand new string object that you just created with the NEW operator. If I now write str1 = null; str2 = null; Then only the String object I created and assigned to str2 above is eligible for garbage collection. The string literal I assigned to str1 above is never eligible for garbage collection. If I now write str2 = "Hello World"; I am re-using the same exact string literal object that I used above and originally assigned to str1. String literals are created for you automatically when your program starts, and they are never garbage collected while your program is running!
I think it has to do with WHERE they are created. Garbage collection recovers space from the heap, but String literals are not created on the heap (don't know where they live, but is is not on the heap), so they are unaffected by gc routines.
Here there is a post that shows how string literal can be g.c.ed strin literals However this is not a normal thing to do. Corey, String s is not a string literal. It gets tyhe value of a string object computed after the concatenations. s will be g.c.ed