User Tools

Site Tools


java:numeric

Java Numeric

Java Supports common Numeric types in the language, as well as less common ones in the standard library (JDK). Except for `char`, all native integer types are signed. By default all numbers extend the Number abstract class.


Signed 32 Bit Integer

Java's default numeric type, int, is a signed, 32 bit, Two's complement integer. Overflow is well defined. The Boxed class Integer contains utility methods for working with ints. Additional support methods are in the Math class.

Signed 64 Bit Integer

Java's large numeric type, long, is a signed, 64 bit, Two's complement, integer. Overflow is well defined.

Signed 8 Bit Integer

A byte is a signed, 8 bit, Two's Complement, integer. Unlike most other languages, a byte is signed, making it somewhat unwieldy. The range goes from [-128, 127]. The JVM stack language does not natively work with bytes, but instead uses integer opcodes to work with them.

Signed 16 Bit Integer

A short is a signed, 16 bit, Two's Complement integer. This type is pretty uncommon in use. Like byte, it has no operators in the JVM stack language, so all manipulation is done with integer opcodes.

Unsigned 16 Bit Integer

The character type char serves as Java's 16 bit, unsigned integer. Typically chars are used in String operations, since Java originally was designed for the UCS-2 code point set. As Unicode grew in code points, a fixed sized character type became less usable. For higher code point, Java stores surrogate pairs in chars.

A character is almost always used with Strings, but be careful when combining them with Strings. For example 'a' + 'b' + “c” will result in numerically combining a and b before concatenating it to the string.

java/numeric.txt · Last modified: by carl