Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Java’s missing unsigned integer types

DZone's Guide to

Java’s missing unsigned integer types

· Java Zone ·
Free Resource

Get the Edge with a Professional Java IDE. 30-day free trial.

This is a topic that has been discussed many times before. Java’s lack of unsigned byte/short/int/long types. The main reasons why the JLS designers omitted those types were:

  1. They’re hardly really useful
  2. They’re a bit more difficult to implement
  3. They’re a bit more difficult to understand
  4. They would lead to more primitive types that have to be treated separately from the existing ones
  5. … and probably, there are more reasons

Nevertheless, these types are sometimes useful for cryptography, image processing, binary protocols, everything related to binary data (why is byte unsigned after all??), and the list of rants in the following ticket at Sun/Oracle is long:

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4504839

For jOOQ, unsigned number types would be useful, as some databases support them (e.g. MySQL, Postgres). And they’re not necessarily trivial to map to Java. So I was looking for a good solution. The best one being to use wrapper classes extending java.lang.Number. So, I have raised the question on Stack Overflow to find such a library:

http://stackoverflow.com/questions/8193031/is-there-a-java-library-for-unsigned-number-type-wrappers

Incredibly, no one seems to have done this – except for some partial implementations in some large libraries. So I’m launching a new OSS project called jOOU – U is for Unsigned. Check out a small library for Java Unsigned Number wrappers:

http://code.google.com/p/joou/

 

From http://lukaseder.wordpress.com/2011/11/20/javas-missing-unsigned-integer-types/

Get the Java IDE that understands code & makes developing enjoyable. Level up your code with IntelliJ IDEA. Download the free trial.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}