Dan Chisholm

Ranch Hand
+ Follow
since Jul 02, 2002
danchisholm.net
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dan Chisholm

Originally posted by Bert Bates:
Hey Dan,

How are you doing dude?!



I'm doing fine.

It looks like you've published a few more books since I was last here at the JavaRanch. I like your Java 5 study guide, and I often recommend it to anyone that's interested in Java and the certification exam. I'm sure that the Java 6 version will also be great when it becomes available this summer.

Also I will try the mock exam suggested by you to test myself.



You must be referring to the link in my signature. My mock exam was developed for Java 1.4. If you are studying for the Java 5 exam, then parts of my mock exam will still be very helpful, but other parts might be beyond the scope on the new exam. For example, the new Java 5 exam does not cover all of the operators that were covered in the Java 1.4 exam. Of course, the new topics that have been added to the Java 5 exam are not covered in my Java 1.4 exam.

It is also important to keep in mind that my mock exam is more difficult than the real Java 1.4 exam. A person that scored above 90% on the real exam might score only about 70% on my exam. My exam was really intended to be more of a workbook for learning Java rather than a tool for predicting your actual score on the real exam.
The passing score is 59% and you scored 82% on the K&B practice exam, so you will most likely pass the real exam. If you are still unsure, then spend a little time on some mock exams.

Is there anyway where I can get a pdf version of this "my book".



I hope not. A free PDF of the book would probably not promote sales of the printed version.

???THIS IS COMPILING???



Yes, you provided an enclosing instance of SearchObjArray for your non-static inner class, ReSortComparator.

In the example on page 557 , why we used a static class to implement Comparator??



The code sample creates an instance of the static member type ReSortComparator within the static context of the main method. A static member type such as ReSortComparator can be created within the context of the main method even though no instance of SearchObjArray exists. If you were to delete the static modifier from the declaration of ReSortComparator, then ResortComparator could not be created within the static context of the main method because an enclosing instance of SearchObjArray would not be available.




If you add the static modifier to the declaration of ReSortComparator, then it will compile.
The problem with my SCJP mock exam web site is now fixed. The hosting company tells me that there was a problem with the domain name.

I'm sorry for long delay. I didn't realize there was a problem until yesterday.

If my web site ever goes down again, then please don't forget that you can find the same content in my book.
[ April 04, 2008: Message edited by: Dan Chisholm ]
The references b1, b2, b3 and b4 all point to exactly the same instance of a Boolean object that wraps the boolean value "true".

The Boolean class contains two static fields, TRUE and FALSE, that are defined as follows.

As shown in previous posts in this thread, the valueOf method returns a reference that is contained in one of those two static fields. In this mock exam question, the reference variables, b1, b2, b3 and b4 were all set by a reference returned from the valueOf method; so all four reference the same instance of a Boolean object that wraps the value "TRUE".

The first of the following three comparisons varifies that the reference values are exactly the same.


The second and third comparisons verifies that the wrapped primitive values are the same.

This question also demonstrates that the valueOf method that accepts an argument of type String ignores the case of the string.
Faisal,

The native modifier specifies an implementation detail that an overriding method is not required to support. For that reason, an application of the native modifier to an abstract method declaration has no impact on the implementation of the overriding method in the subclass. Since the native modifier is useless when applied to an abstract method, the Java Language Specification requires the compiler to throw a compile-time exception to let the programmer know that the modifier has no impact.

The following code example demonstrates that a subclass can override a native method with a new implementation that is not native.



If you attempt to compile the above code example you will see that the compiler does not complain.

For the purposes of the exam the only thing that you need to know about the strictfp modifier is that it is indeed a Java modifier.
Ken,

Thank you for using my exam.

The method name abs is overloaded. There are versions that accept one argument of type int, long, float or double. The type of the return value is the same as the argument type as long as the argument is one of the four types mentioned earlier: int, long, float or double. The magnitude of Integer.MIN_VALUE is one greater than the magnitude of Integer.MAX_VALUE; therefore, the absolute value of Integer.MIN_VALUE exceeds the range of Integer.MAX_VALUE. Due to the limited range of type int, the two's complement of Integer.MIN_VALUE is surprisingly Integer.MIN_VALUE.

If the argument is Short.MIN_VALUE, then the type of the argument will be promoted to type int by method invocation conversion. More specifically, the argument of type short that has the value Short.MIN_VALUE will be promoted to type int and the value will be -32768. The absolute value of negative 32768 is positive 32768, and that positive value is well within the range of type int; so that's the value that will be returned by the abs method.

The abs method is able to correctly calculate the absolute value of Short.MIN_VALUE, because method invocation conversion promotes the type of the argument from type short to type int. The abs method does not correctly calculate the absolute value of Integer.MIN_VALUE, because the argument is not promoted to a type that has a range that is wide enough to accommodate the absolute value of Integer.MIN_VALUE.
[ May 26, 2007: Message edited by: Dan Chisholm ]
Congratulations on your great score Charles!
14 years ago
i *= 2*i + i++;

Jave evaluates expressions from left to right while respecting operator precedence. The first expression encountered is the compound assignment operator, *=. Since E1 op= E2 is the same as E1 = (T)((E1) op (E2)) we can expand the original expression as follows.

i = (int)((i) * (2*i + i++));

Now the first operator encountered on the left is the simple assignment operator, =. The left operand is the variable i and the right operand is the entire expression ((i) + (2*i + i++)), because the simple assignment operator has lower precedence that all of the operators that follow it on the right.

Java will first evaluate the left hand operand of the first multiplication operator, so we can write the value 1 in place of i.

i = (int)((1) * (2*i + i++));

Java will see that the right hand operand of the first multiplication operator is the expression, (2*i + i++), so Java will evaluate the entire right hand operand. The evaluation of the right hand operand begins by evaluating the expresion 2*i. The result is as follows.

(2 + i++)

The next operand is the addition operator. The left operand is the value 2 and the right operand is the postfix expression i++. Both the left and the right operands are evaluated before the addition operation is complete.

(2 + 1)

At this point, the value of i is 2; because i was incremented by the postfix expression.

The result of the above expression is 3, so our original statement can be simplified as follows.

i = (int)((1) * (3)); // At this point, i = 2.

The above can be simplified as follows.

i = (int)(3);

Prior to the evaluation of the simple assignment expression, the value of i is 2. After the evaluation of the assignment expression the value of i will be 3 and the old value will be lost.

Please note that the above process demonstrates what Java does, but it is not the simplest way for people to evaluate expressions. For us, it is a little easier to first go through the entire expression and evaluate the postfix and prefix expression first. On a second pass through the expression from left to right we can then work through the other operators. I didn't demonstrate that approach above, because I wanted to demonstrate when the postfix expression really does increment the value of i.

Please also note that the real exam does not focus on operator precedence. The real exam assumes that programmers use parenthesis to control the order of evaluation.
Congratulations Rebecca!

Yes, I'm a real person. When I was made in Geppetto's workshop I was just a wooden puppet on strings, but now I'm a real person.

Thank you for using my exams!
14 years ago
Congratulations Dilip!

Thank you for using my exams!
14 years ago