Han Shu

Greenhorn
+ Follow
since Sep 03, 2001
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 Han Shu

Even this one can be compiled without error? I am really confused.
package MyPackage;
class P1{
void afancymethod(){
System.out.println("What a fancy method");
}
}
"One file has to have one and only one public class", is it right?
Sorry, but I still cannot figure it out.
Is there any possibility like this: after one thread just finishes setX(), it will release the monitor, and meanwhile the other thread can get the monitor and grasp CPU in turn, which runs check() at once, then it seems that x and y are not equal at that time.
Thank you for helping me!
Can anonymous inner class be declared as final?
Given:

public class SyncTest{
private int x;
private int y;
private synchronized setX (int i) {x=i;}
private synchronized setY (int i ){ y=i;}
public void setXY (int i ) {setX(i);setY(i);}
public synchronized boolean check() { return x!= y;}
}
Under which conditions will check() return true when called from a different class?
a. check() can never return true.
b. check() can return true when setXY is called by multiple threads.
c. check() can return true when multiple threads call setX and setY seperately.
d. check() can only return true if SynchTest is changed to allow x and y to be set seperately.
Which is the answer? I am always confused by synchronized stuff. Please help to explain the condition in this question. Thank so much.
Thank you Ragu!
However, I am still confused by Hashset, Hashtable, Hashmap, which one gurantee to be synchronized, and which on not?
I met two problem with collection when doing Mock Exam. Please help!
1.You need to store elements in a collection that guarantees that no duplicates are stored and all elements can be accessed in natural order. Which interface provide that capability?
A.Java.util.Map
B.Java.util.Set
C.Java.util.List
D.Java.util.SortedSet
E.Java.util.SortedMap
F.Java.util.Collection
I wonder the answer is D or E or both.
2.Which statement is true for the class java.util.Hashset?
A. THe elements in the collection are ordered.
B. The collection is guaranteed to be immutaible.
C. The elements in the collection are guaranteed to be unique.
D. The elements in the collection are accessed using a unique key.
E The elements in the collection are guranteed to be synchronized.
Is the answer should be C and D?
Sorry, I just made a mistake,the answer is A B C E, so that's no problem.
22 years ago
Q. 3
Which methods can be legally applied to a string object?
A.equals(String)
B.equals(Object)
C.trim()
D.round()
E.toString()
Select all correct answers.
The answer is B,C,E. I wonder why B is right and A is not. Thank you for helping?
22 years ago