Kai Li

Greenhorn
+ Follow
since Jun 26, 2000
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 Kai Li

Originally posted by sdev:
What is the result of the following frament of code:
int a=0x67;
int b=0xBD;
a^b
a.0xFF
b.0xDA
c.0x25
d.0xAA
Answer is b
Anyone please explain how the answer is b.


0x67 is 01100111 and 0xBD is 11011010
01100111
^
10111101
____________
11011010 which is 0xDA.
Kai
Congrt! Good Job!
cheers
Kai
Hi,
I just cleared SCJP with 88% a few minutes ago and I am not so satisfied with my score. I would like to thank all the persons here who give me hand. I prepare for the test three weeks by using RHE & Exam cram. One of questions I know I am wrong is related waitforID and I think I got wrong answers. Anyway, thanks all of you for help me here.
best regds,
kai
Hi,
I heard there are 15 minutes before test to fill in some forms or questions. Is it included in the 2 houre or not? Like when you push start then it means the real test will begin? Really need help. Thank you very much..
Kai
The following question from MindQ #37:
37. Which of the following statements about Java's garbage collection are true?
a) The garbage collector can be invoked explicitly using a Runtime object.
b) The finalize method is always called before an object is garbage collected.
c) Any class that includes a finalize method should invoke its superclass' finalize method.
d) Garbage collection behavior is very predictable.
The answer is a) b) c) but I think only c) is correct, can any people give me detail explain since I alway has error on questions about gc? Thanks in advance..
Kai,
hi,
can anybody give me the link to the carl's note? thank you in advance.
Kai,
AWT components get their look and feel from:
a. Programmable painting support classes;
b. JVM drawing primitives;
c. SWING class;
d. Peer classes;
I don't know how to answer this question and I just select d. Can somebody tell me which is correct answer and why?
[This message has been edited by Kai Li (edited July 28, 2000).]
Not exactly, as to P118:
Line 5: c = g; //it means supclass already have the same type as g.
so line 6: g1 = (Grapefruit)c; //cast the same type as g1,it follows the runtime rules of RHE.
In summary, if you want to cast superclass to subclass, only the superclass reference already point to the subclass object,otherwise it will be illegal.
for example:assume Derived extends Base(both are classes)
Base b = new Derived();//b has the same type as the derived.
Derived d = (Derived)b; //it's ok
Kai
yes, the compiler only knows one class must be a subclass of another but as detail,it will not know.

Originally posted by mikeliu:
Hi All,
Please help me clear the doubts.
What will happen if you attempt to compile and run the following code?
1) Compile and run without error
2) Compile time Exception
3) Runtime Exception

1.class Base {}
2.class Sub extends Base {}
3.class Sub2 extends Base {}
4.public class CEx{
5. public static void main(String argv[]){
6. Base b=new Base();
7. Sub s=(Sub) b;
8. }
9.}
I chose the 1, but the answer is 3. I am totally confused! because in RHE, it is ok to case the object reference at run time if one of classes must be a subclass of the other(it doesn't matter which one)(please refer to page118-119 in RHE if you have RHE). Am i missing something?
Mike


When I slove such questions,I first think about conversion then cast.
1. b is a class reference and it could only convert to its superclass.(RHE) Since it's illegal to convert to its sub class,
then it need cast.
2. As to cast,the compiler only check whether you have explict cast and it does not care who is base class and who is subclass.
(So if line 7 no (Sub) before b then it will generate compile error)

3. At the run time JVM will check the cast relationship between two classes.From RHE 118, since sub is a class, the class of the expression being converted must be sub or inherit from sub but base is super class, so it will generate run time exception.
Hope it will clear your doubt.
Kai,
When I do problems about them,I always get wrong answer. What does mean of the column and what's the relationship between column and fonts? How does it influence display and the total characters that they could contain? Really need help and some examples,Thank you very very much!
kai,

Originally posted by tom gong:
I do not understand why line 2 compare a String created at runtime?
1. String java = "java", va = "va";
2. System.out.println(java == "ja"+va);
please help me to understand it,
thanks for help,
tg


In line 1 you create a string in the String pool area, but in line 2, when you use "+", you actually create a new object and that object is not in the string pool area.Although the contents of two objects are same, their memory address are different. Therefore line 2 should print false
Kai

[This message has been edited by Kai Li (edited July 23, 2000).]
When I visited the web page of Tony Alicea and in part 3 about event generated, in the column of Type of Events It Can Generate:
I see MouseMotion event, I am not sure it's correct. Since java Api doesn't include class MouseMotion event and it belongs to MouseEvent. From the cert. objective, state the event classname for any specified event listener interface , and I think we should not inlude MouseMotion event as the answer..
kai
Math.round(-20.8) should be -21 since round means return the nearest int value.