Versions Compared

Key

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

...

According to the Java Language Specification, Section 4.2.1, "Integral Types and Values," the values of the integral types are integers in the inclusive ranges shown in the following table:

Type

Inclusive Range

byte

--128 to 127

short

--32,768 to 32,767

int

- -2,147,483,648 to 2,147,483,647

long

- -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

char

\u0000 to \uffff (0 to 65,535)

...

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

 

un {+}

no

 

+=

yes

 

^=

no

 

un -

yes

 

Wiki Markup
Failure to account for integer overflow has resulted in failures of real systems, for example, when implementing the {{compareTo()}} method. The meaning of the return value of the {{compareTo()}} method is defined only in terms of its sign and whether it is zero; the magnitude of the return value is irrelevant. Consequently, an apparent but incorrect optimization would be to subtract the operands and return the result. For operands of opposite signs, this can result in integer overflow, consequently violating the {{compareTo()}} contract \[[Bloch 2008, Item 12|AA. Bibliography#Bloch 08]\].

...