wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Boundary Values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Boundary Values " Watch "Boundary Values " New topic

Boundary Values

Kanchan K Bulbule

Joined: Jul 19, 2005
Posts: 20
I was wondering why
Integer.MIN_VALUE -1 = Integer.MAX_VALUE
Integer.MAX_VALUE + 1 =Integer.MIN_VALUE
and the same is true for Long !!!
But not for Double and Float may be they represent floating point numbers.

Any clue...?

Priya Jothi
Ranch Hand

Joined: Jul 13, 2004
Posts: 168
It is because once it(int or long) exceed its range it starts to wrap over the opposite range of values.
Abhishek Jain

Joined: Sep 02, 2005
Posts: 26
i would like to add more

2S representaiton for Number type
how 2s addition works...
taking 8 bit number and it can be extended for 32 bit integer

max 8 bit no=01111111=127

now hows 10000000 treated by compiler
compiler after seeing one as left most bit would assure no is -ive
and would convert that value using 2s complemnt

01111111 one 's complement
now add 1 to it this would be the value
10000000 128 but with -ive sign

hence Max8bitno+1=Min8bitNo

got it.........

but this kind of representation is not there for float and double
they are having seperate rep for mantisaa and exponent so they dont work
in this way


SCJP <br />SCWCD <br />SCBCD <br />SCEA Preparing
Kanchan K Bulbule

Joined: Jul 19, 2005
Posts: 20
Thanks all for the gr8 Explanation .

Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

Thanks all for the gr8 Explanation .

Please make the extra effort to write out words such as "great". The extra keystrokes won't cost much in the way of time, and the enhanced clarity will be appreciated by those communicating on a forum with international readership.

Steve Morrow
Ranch Hand

Joined: May 22, 2003
Posts: 657

Along those lines, someone pointed out that he'd read that as "gracht". This led me to the somewhat amusing "grocho". Then I remembered my Italian lessons and "grotto", which actually *does* carry a genuine meaning in English as well.

Then, I just got silly.

At least in Esperanto, I can grok what he was talking about...
I agree. Here's the link: http://aspose.com/file-tools
subject: Boundary Values
Similar Threads
Second order sorting using Comparable Interface
Math.abs(Integer.MIN_VALUE) return a negative vaue,why?