Chad Michaels

Ranch Hand
+ Follow
since Jun 25, 2010
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 Chad Michaels

Katherine Reut wrote:
So MY question is, the PQsort comparator works as Chad and Henry explained, but I am still unsure about where the comparator actually arranges the elements into the sorted order. Is it on line 13 and 14, when the queue is loaded? But then in the comparator, what are the values of the first and second parameters? Where do they come from? Is the first parameter (Integer one) the value of "x" in the for-each loop, and the second parameter (Integer two) the value of the last element added to pq2?

Hi Katherine,

Wow... this post brought back some memories. It's been a few years.

To give you a quick answer to your question: the comparator arranges the elements as they are inserted into the Queue. When a value is added from using offer(), the comparator's internal algorithm passes the existing values in the Queue as arguments to the compare() method and does this until the Queue is sorted. In fact, you can "see" this in action if you add some console statements. Change the code to reflect this:

And also...

So, if you run the above example with the console statements, you'll see when (and how) the items are inserted and sorted. The details of the sort algorithm (like how often it needs to traverse the Queue) used by the comparator is not something that interests me (though I'm guessing it's logarithmic). I'm sure you can search for it online or someone can explain it.

PS: I could be completely wrong with everything I've wrote.
In addition to what Paul said, you are only implementing Runnable. Therefore, your Worker class IS-A Runnable, and is NOT a Thread. So, it can't possibly behave like a Thread (start).

The Runnable interface doesn't have a start(), only run().

A Worker object is only a "Runnable", which can be passed to a Thread, and that Thread can be 'started'.

So, it's like this:
Worker is a Runnable. Can NOT start(), only run().
Thread T = new Thread() is a Thread. This CAN start().
Thread T = new Thread( new Worker() ). Passing a Worker object tells the thread to use Worker's run() and not T's run(). That's all.

Disclaimer: I could be wrong!

Thanks... that really put it in perspective for me. I'll keep all of that in mind... and just learn from this experience no matter what happens.
13 years ago
I recently earned my SCJP. By some miracle, I received feedback on a job I applied to. They're looking for an Associate Java Programmer... someone with 1-2 years of experience.

Tomorrow they're doing the "phone screen". I'm so scared, I might be too nervous and forget everything I know. How do I calm down? And, what type of questions should I expect?
13 years ago

Tom Reilly wrote:

Chad Michaels wrote:I could be wrong about all of this

You are correct. Note that using a single upper case letter as a generic type is just a convention. You could use <PhilMckracken> as a generic type and it would work just fine.

Thanks Tom!
On line 2, you're trying to use a new type parameter, but it's the same type as the class type parameter. So, either get rid of <T> or just use something different, like <Z>.

On line 6, you're simply saying the method will return a type of the class type parameter.

On line 9, I don't know what you're doing. You're trying to return a type on a void return method? What are you trying to do there? Get rid of the T and it should work fine.

Disclaimer: I could be wrong about all of this... it's just a quick opinion.
I am trying to begin preparation for the OCPWCD exam (SCWCD) J2EE 5. In about one week, I will receive a book in the mail to assist me in studying. Until that book arrives, I only have access to an older book focusing on the same exam, but using J2EE version 1.4 (the older 310-081 exam).b

Would it be helpful to start studying using the old book of J2EE 1.4, or should I just wait another week until the new book with J2EE 5 arrives?
Recently passed SCJP. When I log into certmanager, I see the "download logos" link under downloads, but it is completely empty. Can someone please tell me how this logo thing works?


I know that feeling of getting discouraged, but you have to be persistent! I first went through the book very fast. Then, I went through a second time very slow and made personal notes on everything I did not understand (I think I had over 100 typed pages of notes). Aftering reviewing my notes, I then started practicing mock exams, and thoroughly investigated every problem I got wrong. You can get this. Maybe you can do it quickly, or maybe it will take some time. Just stay focused and be determined.
Enthuware was perfect! Completely prepared me for the real exam!
13 years ago
But, I do not want to focus on passing, and instead, want to offer my opinion to those still studying.

First, do not get discouraged if your progress is slow. Although many people only study 2 months then easily pass, I am not one of them. I exhausted myself for about 8 months, and only saw significant progess in the past couple weeks. Although I felt comfortable with the concepts and understood them, for some reason I could not perform well on mock exams... always averaging around 30-40%. Many times I almost gave up, but I didn't. I just kept going, bit by bit.

I think the first step is to read the K/B book, which is perhaps the best written Java book ever created in the history of mankind. Go through the book a few times and create your own review notes. Then comes the fun part - mock exams, mock exams, and more mock exams.

The best decision I made was to purchase exam-preparation software (I personally used Enthuware). If you stick to any of the reputable exam-prep programs (ExamLab, Whizlabs, etc), you should be just fine. The books are great to develop an "understanding", but the practice exams put that knowlege into practical use.

Overall, don't forget about the basics! I spent so much time studying the concepts that were hard, and almost forgot about the easier things that I take for granted. This was reflected in my score, as I scored the lowest on OO Concepts and Fundamentals, and scored the highest on Concurrency and API Contents (100% on both). Not underestimating the basics is very important!

Again, if you are struggling, get some exam-preparation software! They work! You will watch your mock exam scores go higher and higher! You can do this!
13 years ago