jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Jiris, Mock 1, Q17 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Jiris, Mock 1, Q17" Watch "Jiris, Mock 1, Q17" New topic

Jiris, Mock 1, Q17

Cathy Song
Ranch Hand

Joined: Aug 24, 2003
Posts: 270

Can someone explain line 1, 3 please? Thanks.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Cathy Song:
Can someone explain line 1, 3 please? Thanks.
The byte and short are promoted to an int, made positive and compared to zero.
I would have thought that line 2 would have confused you more than line 1 and 3.

Line 2 is false because of this rule of the abs method:
Note that if the argument is equal to the value of Long.MIN_VALUE, the most negative representable long value, the result is that same value, which is negative.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Cathy Song
Ranch Hand

Joined: Aug 24, 2003
Posts: 270
Hi Thomas,
I knew about the rule regarding Long/Integer. I thought the same applied to Byte/Short.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
An easy way to remember this is:
Integer.MIN_VALUE is 80 00 00 00
Without having looked at the code source I suspect that Math.abs calls ~ on the int or long argument ad then adds 1.
~80 00 00 00 = 7F FF FF FF
7F FF FF FF + 1 = 80 00 00 00

SCJP2. Please Indent your code using UBB Code
I agree. Here's the link: http://aspose.com/file-tools
subject: Jiris, Mock 1, Q17
It's not a secret anymore!