Keith Nagle

Ranch Hand
+ Follow
since May 06, 2008
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 Keith Nagle

Hi guys, quick question about the reserveDVD and releaseDVD methods on pages 154 & 155 of the
SCJD book (Monkhouse & Camerlengo).

Can someone please explain the reserveDVD and releaseDVD methods to me in Layman's terms?

I've tried to get my head around these 2 methods but can't seem to.

Mainly the questions I have about the reserveDVD method are

If a thread acquires the lock, what is the point in it having to invoke

If a thread get's the lock, will this "if" statement wait immediately return true? Or, will 5 seconds always and then true will be returned.

Also, above all, if a thread can't obtain the lock by calling "lock.lock()" and blocks, how does the "if(!lockReleased.await(timeLeftMSec, TimeUnit....)" statement help us?
The reason I ask, is that if the lock is released and our blocking thread picks up the lock and enters the running state, the "if(!lockReleased.await(...))" will never
return false.

Any help greatly received,
Excellent guys will take a look at the singleton pattern in more detail. I should've done this in the first place!
Thanks again.

P.S. Congrats on your SCJD score Roel - really impressive! ;)
Hi there. I am working through the great SCJD book by Andrew Monkhouse & Terry Camerlengo.
Unfortunately I have run into something that I can't make sense of!

On page 138, a decision is made to [b]not[b] make the DVDFileAccess class a singleton.
The issue is that I'm having trouble figuring out why this decision was made. It's not entirely clear to me.
The decision is based around 2 points:

The first states that a lot of work can be performed in parallel if multiple clients are working on a CPU system.
Am I correct in stating that based on this point, it doesn't make sense for this class to be a singleton as
in a multi-threaded environment this singleton instance would be acting as a mutex??

The second point states that if DVDFileAccess was made a singleton, then any class that leverages the
DVDFileAccess class would have to be coded differently. My question is why? It's not clear to me.

If anyone can clear up these two points, I would really appreciate it!

Many thanks & Regards
I have the same problem.
I paid for the assignment, all �365, over the telephone.
I then received a voucher number for my assignment.
And then... nothing.
I logged into certmanager ( where I could see a link to download the assignment but the permissions were inadequate.
I then emailed suncert and was informed that I had "purchased a voucher to pay for the assignment, not the actual assignment", whatever that means.
The reply also indicated that they had not received a request to give me permissions to download the assignment - why I do not know.
Also I was asked to forward the sun training product order if I had purchased the assignment online, which I didn't.
So I have now received an email to say that the assignment permissions request has been forwared on, at last.
All in all, a painful, unprofessional and opaque process for obtaining the SCJD assignment.

[ August 20, 2008: Message edited by: Keith Nagle ]
[ August 20, 2008: Message edited by: Keith Nagle ]
The question must be wrong.
Assume that we are working with class files instead (MyClass.class)
of .java source files and answer b is correct,
also assuming we use the java launcher instead of javac.
Classpaths on the command line override the system variable
classpath and it will also evaluate the classpath from left to right.
[ July 27, 2008: Message edited by: Keith Nagle ]
CharSequence is an interface.
Look at F, this answer is the correct version of G.
Looking at the type parameter for G <E super CharSequence>
would imply that you are declaring E as a CharSequence or a
super entity of CharSequence, not something that implements the CharSequence interface. It is an interface, so you
have to have the keyword extends which means a type that "implements" or
"is-a" CharSequence. Read page 593 again.
Best regards
the compiler also needs to know classpaths.
How else could it find the standard libraries?
If you have a program that imports other classes you wrote
that are in packages, how else would the compiler find them?
As well as the java launcher, the compiler also needs classpaths.

For the above question, you need to omit the system classpath, as this is overridden by a command line -classpath switch.
And finally, remember that /foo/bar/baz is an absolute path, not a relative path, so the compiler looks in the baz directory, which resides at /foo/bar/baz.
Best regards.

[ July 27, 2008: Message edited by: Keith Nagle ]
[ July 27, 2008: Message edited by: Keith Nagle ]
It does seem a little confusing but I read this article from sun (regex) and it
helped me understand. What helped me nail it, was by practicing with some code examples. Copy the code from the sun article and play around with some patterns and input strings. I guarantee you will get the hang of it if you do!
Best of luck

Have a look at the above link I posted and then check this out!
[ July 24, 2008: Message edited by: Keith Nagle ]
I used the 2 minute drills a lot (and I still do for that
matter, even after I passed).
I read the book thoroughly the first time and the second
time I skimmed over it, paying meticulous attention to the
code examples and 2 minute drills. Everything came together
at that stage. Best of luck with the exam
I think the golden rules to remember here is
that an int CANNOT become a LONG (widen & box) and an
Integer cannot be widened to a Long as they
are peer classes!If you remember those you will
be at your grannies.
Best of luck with the studies.

Originally posted by rakhee gupta:
Why not objects referenced by e2 and e3 along with e3 are eligible for GC after line 3 after all their references(e2,e3) also being set to null?

Again, forgetting about the NPE,
Objects referenced by e2 and e3 are not eligible for GC as
they are still accessible by any live thread via references
e1.e and e3.e
You have to try and visualize it!
Best regards.

Originally posted by Ralph Jaus:
Hi Keith, the statement is definitely wrong in general. It is correct in your example

int collarSize = 3;
{ collarSize = 10; }

because there is at first a variable declaration/initialization and afterwards the init block. And that's just the order the compiler takes.
If your int block would be followed by a declaration/initialization of a variable, say

int i = 7;

it would be processed next, that means after your init block !!

Yep, I should have stated that my statement pertains to my example, not in general.A simple typo - my bad!
Bear in mind that when you talk about the order and the compiler above, you really mean the JVM and not the compiler? Instance init blocks are executed at runtime, when new is invoked on an object
Kind regards,
No. In the context of my code above, it is not wrong.
Look at the disassembler output from my last post.
Your instance init blocks don't give the instance
variables their values. They only print numbers.
if they did assign values, you would find that
they do so in the order of the statements.
best regards
[ July 16, 2008: Message edited by: Keith Nagle ]
Heres the example code:
<pre name="code" class="core"> class Animal {
class Dog extends Animal {
int collarSize = 3;
{ collarSize = 10; }

public static void main(String[] args) {
new Dog();

And if you compile this and use the java bytecode disassembler javap like so (after you have compiled the Dog class using javac):
<pre name="code" class="core"> javap -c Dog </pre>
you get the following output:
<pre name="code" class="core">
Compiled from ""
class Dog extends Animal{
int collarSize;

0: aload_0
1: invokespecial #1; //Method Animal."<init>" : ( )V
4: aload_0
5: iconst_3
6: putfield #2; //Field collarSize:I
9: aload_0
10: bipush 10
12: putfield #2; //Field collarSize:I
15: return

public static void main(java.lang.String[]);
0: new #3; //class Dog
3: dup
4: invokespecial #4; //Method "<init>" : ( )V
7: pop
8: return


You can see that in main, new is invoked which kicks off Dog's constructor.
Looking at the bytecode for the Dog constructor, Dog's "this" reference is pushed onto the operand stack and then Animal's constructor is invoked.
Next Dog's "this" reference is again pushed onto the stack. The int value 3 is also pushed onto the operand stack and then putfield assigns 3 to collarSize. The values are then popped from the stack. Finally 10 is assigned to collarSize and Dog's constructor returns.
So in a nutshell, it seems that instance variables are given their assigned values after the call to super() and before the instance init blocks run.
Correct me if I am wrong!
Javap is great to play around with if you have the time and interest.
Hhmm, maybe I have too much time on my hands
Best regards.

[ July 16, 2008: Message edited by: Keith Nagle ]
[ July 16, 2008: Message edited by: Keith Nagle ]
I often wonder about this myself
Well, like you said, static initialization blocks
will run when the class is first loaded by the JVM.
Then what happens next Dog instance variables will be given their
default class values. Then the call to Animals constructor (super())
is invoked. Then when this call returns, your Dog instance variables will be given their initial values (say x = 9...) then I would imagine the
instance initialization block would run. I cant see it running before
your instance variables are initialized.
Let me look into it
best regards