Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!

Ray Hsieh

Ranch Hand
+ Follow
since Sep 20, 2000
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 Ray Hsieh

When a thread acquires a lock, it prevents other threads from acquiring the same lock until it has released the lock. A thread can acquire the same lock multiple times (locks in Java are reentrant), for instance:

A thread can also acquire one lock, and then proceed to acquire another lock, like this:

Originally posted by Pho Tek:
I want to implement a service that accepts subscription requests from many threads.

Since the state "subscribed" is a global condition; only one request should be entertain.


Sounds to me like a wait/notify scenario. Do the threads have to queue or any of them can get processed as long as it's one at a time? How many threads are processing subscription? etc. etc. Like Henry said, we really don't have enough info about what you're trying ot do to tell whether you're going in the right direction or not with this one.
Well, to be sure, create a thread dump. If it's on Windows you press Ctrl + Break. For example, if we have an obvious deadlock like this:

Then pressing Ctrl + Break on Windows gives you a bunch of text that highlights the deadlock like this:

... a lot of text ...

Found one Java-level deadlock:
waiting to lock monitor 0x02a807cc (object 0x2405edb0, a java.lang.Object),
which is held by "Thread-0"
waiting to lock monitor 0x02a82094 (object 0x2405edb8, a java.lang.Object),
which is held by "Thread-1"

... a lot more text ...

If you name your threads properly, you can see that this info can be very useful.

Originally posted by Pat Farrell:
1.6 update 6 is latest stable. But can I ask, why change? Java 6 brings nearly nothing over 1.5. I would think long and hard before migrating working code. New code, sure, I'd start with Java 6.

If we're talking about syntactic sugar or language features addition, sure, Java 6 brings little over 1.5. But beyond that, there are many reasons why one would want to change to Java 6:

1. Better Swing performance
2. Better facilities to monitor running production systems
3. Better error messages on memory problems
4. Improved performance
5. Improvement in the garbage collectors

etc., etc.

Even if you're not using Swing, your server apps will still benefit from the rest of the enhancements.
11 years ago
There's an easier way, just use the TimeUnit enumeration from java.util.concurrent.

To make a thread sleep for 1 minute, you do something like this:


To make it sleep for 30 seconds:


And so on.
Hi Victoria, I think it's because now you only have 90 mins instead of 2 long hours Lots of questions contain short code snippets as well.. so you have to be quite used to reading code quickly.

Originally posted by Victoria Bernstein:
Hi folks,
Does anybody know why the passing score is only 61% comparing to 71% before? Is the exam much harder and if yes, then in which way?
Thanks a lot

Thanks all! Yeah Shubhangi, I'm brewing a "killer" potion here! My company is in the B2B field.. so everyone is expected to be proficient at brewing this potion!

19 years ago
Hi Eric,
I was given lots of paper and a pen... I only used one of them, though.
19 years ago
Thanks all! Yeah Ajith, see you there! Good to hear that it actually exists
Deepak, JLS (Java Language Spec.) is downloadable for free, and no, I don't have any notes about that.. too lazy to type my thoughts.. I'd rather organize it inside my head...
Shan, that's the least I could do, after learning a lot of things from this wonderful site
There was a weird question about Thread (that's the one that I missed, I think).. too bad I can't discuss it cos I can't tell you guyz what it is Oh well...
19 years ago
Thanks rajani!!
I'm really happy that I'm done with this exam thing
Might be going from some other cert.. like XML for IBM (does such thing really exist?) Never mind, will find out!

Originally posted by rajani peddi:
hi Ray Hsieh
Congratulations!!! thats a very good score. and also thanks for all the info about the exam.....

19 years ago
Hi all!!!
I'm very happy... just passed the SCJP2 with 94%
I'd like to thank JavaRanch and every single one of you, the participants, those who have come up with interesting questions... tho I don't speak out that often.. but I lurk in the dark silently, watching you guyz discussing.. oooo..
The first impression that I got from the test was that some of the questions were designed to trap C++ guys (like me).. (glad to say they didn't succeed though) For instance... in C++, if a function doesn't have a "throw clause", it means it can throw *anything*... but that's not the case in Java! And.. no no no, you can't "flatten" a supposedly two dimensional array by "reinterpret_cast<>"-ing it in Java, heheheh
Most of the questions are easy, but be careful! Sometimes when you think that a question is about something, it is actually ABOUT SOMETHING ELSE! I mean, you might think that the question is about loop, you've gone through it manually, but later when you review it, you realize that the code actually won't compile cos it references an instance member from a static function.. or something like that..
I missed 1 on Thread, 1 on AWT (ouch!), 1 on Overloading.
Preparation was short and hectic.. I only did Marcus's mocks (thanks Marcus!), tried Khalid's mock once (and got 59%, I think ), and that was it. I didn't have the patience to go through all the mock exams out there, and *personally*, I don't think it's necessary, as long as you get the concepts clear.
Regarding the books.. if your budget is tight, buy the one by Khalid, it's REALLY REALLY good. And download the JLS and read it! It's really good for your fundamentals (but I think my C++ experience helps a lot in reading this.. don't think it'll be suitable for people with no programming experience).
I read JLS and Khalid, except for I/O, Thread, Layout Managers, and Collections. For these 4, the best resources (I think) are:
1. I/O: Thinking in Java, Bruce Eckel (chapter 8 I think.. not sure, too lazy to check it out )
2. Thread: the Thread book by Paul Hyde.. but Khalid's discussion is also good.
3. Layout Managers: "Effective Layout Management" tutorial from Magelang Institute. Personally, I think this is THE BEST tutorial about Layout Managers out there. Oh yeah, one question bout GBL. AND "The Java AWT: GridBagLayout" by Jan Newmarch, which, I think, explains GBL the best! (
4. Collections: "Introduction to Collection Framework" tutorial from Magelang Institute.
Time--I managed to go through the exam twice. If you think you've come across a question that needs some extra thought, mark it and move on.
Things to know:
1. I/O constructors (especially for FileIn/OutputStream)
2. What do the layout managers do?
3. How to override a method correctly? What are the things you can and cannot do? *VERY--REPEAT--VERY IMPORTANT*!!!
4. What are the mechanisms to "signal" another thread that I have done something on my thread?
5. Get the concept about public, protected, "default", and private as clearly as possible!
6. Default constructor, what are they? How do they work? Why are they there?
7. What does each interface in the Collection Framework do?
8. Everything in Java is passed by value!!! *IMPORTANT*!
9. Strings are immutable...
The others are really about the fundamentals.. like promotion.. assignability.. casting.. 1 question on Math class..
Oh, btw, I don't have the patience to write down everything.. so.. no notes
Kay, that's all, I guess!
Thanks again all!
Ray Hsieh
[This message has been edited by Ray Hsieh (edited December 04, 2000).]
19 years ago
Hi asim,
But the compiler and the interpreter "eat" different kinds of file. I think she meant those *.java files, not *.class files.
Anyway.. for both jikes and javac, empty files seem to be okay

Originally posted by asim wagan:
Hi! i think it in two senses it is a valid file when it is for the compiler it compiles it correctly. while it is not valid for the interpreter.So, explain it in which sense you like it.

From the JLS, the ForUpdate part (i.e.: the ++i/i++ part) is evaluated first before another iteration is performed. So... I don't think it matters whether it's a prefix or postfix, doesn't it?

Originally posted by Sahir Shah:

what will this print
for(int i = 0; i < 1; i++)

and what will this print

for(int i = 0; i < 1; ++i)

Try it out first beofre you post an answer.

Hi all,
Just wondering--I just bought my voucher, and I got a package containing some info about how to contact Sylvan, the objectives, and program details. I was surprised to see that the passing score is still 71%, and the test time is still 2 hours...
Did they give me an outdated package, or what? I thought the new exam was available worldwide.. but realized that the java page at sun was for the US.
Has anyone taken the exam in Asia, especially Singapore?