Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!

Philip Heller

+ Follow
since Oct 24, 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 Philip Heller

The SCJP exam tests your knowledge of Java, not your ability to convert hex or binary to decimal. As long as you understand 2's complement, you'll be fine.

-- Phil
Those are the only 2 cases. The other 2 versions of Math.min (the float and double versions) don't return any negative values, though they might return NaN or positive infinity.

-- Phil
Sherry, you're getting an "inconvertible types" message, right? Here's the deal:

instanceof is for situations where you can't know the result until runtime. In your code, the compiler has realized that the result can't possibly be true under any circumstances, so there's not much point in creating bytecode to do the obvious. This is one of those cases where the compiler clears its throat and says, "Excuse me, but there's a better way to do this."

You'd be in a similar situation if you tries to cast falcon to Transport. Again, the compiler knows at compile time that the cast can't possibly work. Rather than making you wait until runtime (when you would get ClassCastException), the compiler posts an error as soon as the illegal cast is detected.

"falcon instanceof Transport" is like an illegal cast detected at compile time. Both result in compiler errors.

"falcon instance of SomeSubclassofF16" is like a cast that compiles but causes ClassCastException at runtime.

"falcon instaneof Fighter" is like a legal cast.

For obvious reasons I'm partial to "Complete Java 2 Certification".

-- Phil
When an assertion error is thrown, the stack trace and optional text are printed and then execution stops. More on assertions in Chapter 5 of "Coplete Java 2 Certification".

- Phil
Sherry is right ... static variables are created when the class is loaded.
Shifting isn't covered in the 5.0 exam. Check out objective 7.6, which lists all the operators you need to know about.

-- Phil
In class Double, the valueOf() method is static. If you check the source code, you'll see that the method is just one line:

So there's the constructor call you were wondering about.

-- Phil
4.999999f is internally represented by the same bit pattern that represents 5.0f. Check out this code:

The output is:

4.5 is represented as 1083179008
4.4999999f is represented as 1083179008
4.499999f is represented as 1083179006

The last representation has a 6 in the ls digit.

-- Phil
A, B, C, and D are true statements. E is false because a cat is not a specific kind of dog.

-- Phil
Sometimes I've wanted an abstract synchronized method, to enforce synchronized behavior on all subclasses, but the compiler won't let me. I can imagine heavy-duty number crunchers wanting to create abstract strictfp methods, again to enforce behavior on all subclasses, but again it's illegal.
The 5.0 rev of "Complete Java 2 Certification" is out. I also have written a supplemental document that goes into more depth on writing custom generic methods. If you want a copy, send me a private message with your email address.

-- Phil
The 5.0 rev of "Complete Java 2 Certification" has been available for a few months. It covers all the material for the 5.0 exam.

After the book came out, I realized I wished I had gone a bit deeper into writing custom generic methods. So I wrote a supplement, which will soon be on the website. But the easy way to get a copy, for you or anyone else reading this, is to send me a private message with your email address.

Good luck!

-- Phil
I just checked the SunEd website, and they still sell the 1.4 exam.

-- Phil
Rick -

"Dibbles" and "Tribbles" ... love 'em!

Another issue is the arithmetic concersion issue. If two dibbles, represented as bytes, are to be multiplied, Java will convert the bytes to ints. Then after the multiplication, the result has to be cast back to byte. If arithmetic isn't carefully managed, all the conversion and casting could chew up a lot of time.

Thinking out loud here, I would be tempted to use lookup tables for arithmetic. Suppose I want to multiply a pair of dibbles, one in bits 1:0 of its byte and one in bits 3:2 of its (different) byte. Assuming all other bits are zero (that is, the other dibbles or tribbles have been masked out and I'm now dealing with ints), I would add the dibbles and use the result as an index into a byte array. I would have one array for addition results, one for subtraction, etc.

I'm really enjoying typing "dibble" and "tribble" so I'm going to do it once more before signing off. Dibble. Tribble.

-- Phil
14 years ago