Ana P

Greenhorn
+ Follow
since May 02, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ana P

how can in while loop b++ calculates -128
binary value of 127 is
0111 1111
+ 1
-----------
1000 0000
pls explain...
byte b1 = 1;
while ( ++b1 > 0 );
System.out.println(b1); //prints -128 ???
System.out.println("Welcome to My World!");
[ May 15, 2002: Message edited by: Ana P ]
GC
Thx this does help.
I just wnat to make sure that string literals are not garbage collected
GC
http://www.javaprepare.com/notes/classes.html
see this site
last q says that string literal is eligible for garbage collection
public class GCTest {
public static void main(String args[]) {
String a,b;
String c = "test";
a = c;
c = null; // The String "test" is not yet
//available for GC as a still points to "test"
b = new String("xyz");
b = c; // String "xyz" is now available for GC.
a = null; //String "test" is now available for GC.
}
}
a = null; //String "test" is now available for GC.
I think string literal are not garbage collected
double d21=10.3;
float f21=10.3f;
System.out.println("d==f " + (f21==d21));
if(f21==d21)
System.out.println("d==f=true");
This does not return true for all values
like 0.9. 0.5
I think while promotion it loses precision.
am i right?
char ch = '1' + '8';
System.out.println("ch= " + ch); // prints i
char ch2='2';
char ch3='1';
ch3 += ch2;
System.out.println("ch3= " + ch); // this also prints i
why so?
double d=0.9;
float f=0.9f;
System.out.println("d==f " + (d==f));
if(d==f)
System.out.println("d==f=true");
I tried this , but got answer d==f as false
n a Java program, if the Unicode escape sequence \u000A, for example, occurs within a single-line comment, it is interpreted as a line terminator (Unicode character 000A is line feed) and therefore the next character is not part of the comment.
Similarly, if the Unicode escape sequence \u000A occurs within a string literal in a Java program, it is likewise interpreted as a line terminator, which is not allowed within a string literal.
One must write \n instead of \u000A to cause a line feed to be part of the string value of a string literal.
Because Unicode escapes are processed very early, it is not correct to write '\u000a' for a character literal whose value is linefeed (LF); the Unicode escape \u000a is transformed into an actual linefeed and the linefeed becomes a LineTerminator, and so the character literal is not valid. Instead, one should use the escape sequence '\n. Similarly, it is not correct to write '\u000d' for a character literal whose value is carriage return (CR). Instead, use '\r'.
Look at this example...
class Super{
public Super() //1
{
a();
}
void a() //1
{
method();
}
void method() //3
{
System.out.println("1");
}
}
public class Subclass1 extends Super{
public Subclass1()//4
{
a();
}
public void method() //5
{
System.out.println("2");
}
public static void main(String []args) {
Super c = new Subclass1(); // 4 - 1 - 3
}
}

The output of this prog is 2 2
I thought it should be 1 2
how this works?
Super c = new Subclass1(); // 4 - 1 - 3
after this line control will go to super class constructor. and then method a() at 1 and then call to method at 3. but it does not work that way
pls explain...
Hi June,
Heartly congrats.
Pls do share ur exp. with us.
21 years ago
Hi,
I am really confused about garbage collection mechanism of string objects. Can anyone help me on this topic.
I read it somewhere that
String objects created like :
String a="abc" will not be garbage collected
while String a= new String("abc") will get gc' ted.
String a,b,c;
a="abc";
b=a;
a=null;
then how many objects will get garbage collected and when?