Java - Unsigned integer


Unsigned integer by design is absent in Java language. This is one of the most important differences between C and Java. In C "unsigned" is often used for hardware communication, size variables and encryption algorithms. Java lacks this feature, but there are some workarounds for this problem - see below.

Why and when unsigned is needed?

See: Unsigned int considered harmful for Java.

Built-in APIs

You can use "Unsigned Integer API" available since Java 8. It's not a new primitive type, just a set of functions which allow to use standard Java's integer as unsigned. Look for "unsigned" in java.lang.Integer.



Library home: jOOU, documentation: jOOU JavaDoc

Implements unsigned versions of Java's boxed integer types: UByte, UShort, UInteger, ULong

Guava - UnsignedInteger and UnsignedLong

Guava library has a part responsible for unsigned integer support.

Introduction: Unsigned support.

Documentation: UnsignedInteger and UnsignedInts.