Haining Mu

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

Recent posts by Haining Mu

Originally posted by Mathias P.W Nilsson:
Great score Haining! I'm up in about 2 weeks. I must say I'm still week on Threads and io. Did you just read Khaild's book and RHE or do you have other suggestions?

Khaild's book should be enough if you do remember everything in there. you may need read carefully and practice on thread cuz most of us don't have much experience programming that. I do have 3~4 questions on sync. 2~3 on contructors and 2~3 on its methods. for IO, normlly remember contructors should be OK, but I do have a question regarding its methods.
beside book and mocks, I do read some chapters of JLS, it will help you to clear the doubt, expecially on override, overload, etc. For some class like "String", "Math", you do need to know what exactly method does by reading through javadoc.
good luck
22 years ago

Originally posted by Ashik uzzaman:

Congrats Haining! Great score!!
How many questions were on I/O and how much time did u take? Did u use JQ+/J@Whiz?

I had at least 5 questions on I/O, 4 of them are test constructors. I spent less than an hour to answer all questions and marked about 5 to review. enough time to check second time.
i didn't use JQ+/J@Whiz cuz they are NOT free.
22 years ago
missed two questions, one in inner class, one in thread.
for those who are giong to take exam, these two topics must be read through. a lot of questions from there. for IO, various constructors are important. I don't have any filling blank question.
I read Mughal, Exam Cram and Roberts, found Mughal is most useful to get high score.
I took every FREE mock exams avaiable through this site.
22 years ago

Originally posted by anand raman:
the answer will not be affected by just changing the data type of the variable a. As i understand it, the return type of ternary operator is determined by the types of the true and false option. The return type will be determined by the larger option.

NOT absolutly right. for this code:
System.out.println("Value is - " + ((3 < 5) ? 9.9 : 9)); will give output "9" instead of 9.0 although double is widen than int here.

Let me try to explain with rules in JLS 15.12 - method invocation. At complie time, we need determine method signature. According to JLS the most specific method. Here are the rules:

If more than one method declaration is both accessible and applicable to a method invocation, it is necessary to choose one to provide the descriptor for the run-time method dispatch. The Java programming language uses the rule that the most specific method is chosen.
The informal intuition is that one method declaration is more specific than another if any invocation handled by the first method could be passed on to the other one without a compile-time type error.
The precise definition is as follows. Let m be a name and suppose that there are two declarations of methods named m, each having n parameters. Suppose that one declaration appears within a class or interface T and that the types of the parameters are T1, . . . , Tn; suppose moreover that the other declaration appears within a class or interface U and that the types of the parameters are U1, . . . , Un. Then the method m declared in T is more specific than the method m declared in U if and only if both of the following are true:

T can be converted to U by method invocation conversion.
Tj can be converted to Uj by method invocation conversion, for all j from 1 to n.

So for your question:
case 1:

both method yy(int i) and (long i) are accessible and applicable. But here A can NOT convert to B although int i can convert to long i. Similarly, B can convert to A but long i can NOT convert to int i. Therefore, neither method is SPECIFIC to the other, you got ambiguous complie error.
case 2:
if you change b1.yy(3); to b1.yy(3L), only ONE method is applicable, it is yy(long i).
case 3: interesting one if you change B b1 = new B() to A b1 = new B(), ie.

you get result 3, because at compile time, type A (variable b1) has only ONE method applicable. If you now change the call to b1.yy(3L), you got compile error for method not found.
case 4: if you switch method in A and B, declare bi A;

you got output 3 although int parameter is passed, at compile time, only ONE method is applicable.
case 5: this is the case that one method is more specific than other

you got output 6. Because you have two method again applicable and B can convert to A and int i can convert to long i, B's method is more specific than A's. This is the same as you define two methods in same class in the example.
Overloaded method is choosen at compile time, overriden method at runtime, they are different.
hope this helps. please indicate if I am wrong.

[This message has been edited by Haining Mu (edited June 22, 2001).]
[This message has been edited by Haining Mu (edited June 22, 2001).]
the B's constructor you call is B(String s), the compiler will insert a "super();" if the first line is neither this(...) nor super(...). So A() is called.
[This message has been edited by Haining Mu (edited June 22, 2001).]
while not frequently used, we still can find examples of inner interface:
Map.Entry in Map
JComboBox.KeySelectionManager in JComboBox
Answer is A, D.
There is explaination for D in JLS 8.4, it is allowed but old fashion.
to override a method int[] myMethod() in superclass, which of
the following is(are) legal in subclass (select 2 correct answers):
a)int[] myMethod(){...}
b)int myMethod(){...}
c)int myMethod[](){...}
d)int myMethod()[]{...}
e)[]int myMethod(){...}
hi all,here is the samle code from JLS regarding field initialization, I already comment-off what author marked "error", but it still have problems of "forward reference". I also include error from javac. Can anybody explain? Does the author wrong, or Sun's compiler does not strict follow JLS?


you can see the original here:
[url = http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#287406

[This message has been edited by Haining Mu (edited June 19, 2001).]
[This message has been edited by Haining Mu (edited June 19, 2001).]
Is this correct: wait() is an instance method of Thread class

Originally posted by Thomas Paul:
The JLS explains it here:
The problem is that you are attempting to store an infinitely long number (1/49) within a fixed length field. This is obviously impossible. Rounding/truncation has to occur on the fraction. So when you multiply (1/49) * 49 you do not get 1.

thanks. i was expecting this happen for (1/49) * 49 not equal 1. but why (1/3.) * 3. equal 1. Just remembering somewhere in the book mention these kind of comparison is NEVER true. Hope we shuold have no quesiton in EXAM like this.
[This message has been edited by Haining Mu (edited June 15, 2001).]

Originally posted by Jyotsna Umesh:
Q. If you compile the following code what will be the result?
public class MyClass {
public static void main(String args[]) {
String str1 = "Test One";
String str2 = new String("Test One");
if ( str1.equals( str2) ) {
System.out.println("Both are equal");
boolean b = true;
boolean b1 = false;
if ( b.equals(b1) ) {
[a] Compile time error
[b] Runtime error.
[c] No output
[d] "Both are equal" followed by "true"

Compile error, equals() method can not be used for primitive. though first part will be "equal"
reading JLC and have a doubt:
double d = 1/3.;
System.out.println((d*3 == 1)); //true
double d = 1/49.;
System.out.println((d*49 == 1)); //false
not quite understand, can anybody explain? thanks.