Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If the result of the addition is greater than the maximum value or less than the minimum value that the int type can store, then the variable temp will contain an erroneous result. Although unlike C\/C++ integer overflows are difficult to exploit due to of the memory properties of the Java platform (e.g., explicit array bounds checking, if temp has a negative value as a result of an overflow and it is used as an array index, we get a java.lang.ArrayIndexOutOfBoundsException), the issue can lead to undefined or incorrect behavior.

...

Operator

Overflow

 

Operator

Overflow

 

Operator

Overflow

 

Operator

Overflow

+

yes

 

-=

yes

 

<<

no

 

<

no

-

yes

 

*=

yes

 

>>

no

 

>

no

*

yes

 

/=

yes

 

&

no

 

>=

no

/

yes

 

%=

no

 

|

no

 

<=

no

%

no

 

<<=

no

 

^

no

 

==

no

++

yes

 

>>=

no

 

~

no

 

!=

no

--

yes

 

&=

no

 

!

no

 

&&

no

=

no

 

|=

no

 

un +

no

 

||

no

+=

yes

 

^=

no

 

un -

yes

 

?:

no

Addition

Addition (and as with all arithmetic operations) in Java is performed on signed numbers only as unsigned numbers are unsupported.

...