Unsigned Primitives

Why doesn’t Java have unsigned primitives? I can never wrap my head around this. How hard would it be to implement unsigned arithmetic? Every single other strongly typed language out there has them!

I love Java, but this always bothered me. Java does not exist in a vacuum. Sure, when you are working in pure java environment, with pure java standards, and data formats you are fine. But in the real word, sometimes data uses non-java friendly conventions. Especially in imaging. Most images use unsigned ints or bytes to store pixels. Sure, you can always use an int to store a byte but this is wasteful.

Furthermore, most of Java API’s work with signed data. If you are just crunching numbers, this is usually not a big problem - but if you try to do something more fancy you run into issues. For example - awt package has some nice image display capabilities. I do not feel like implementing a rendering algorithm for my data. I also do not want to use JAI, because it is not standard, not mature enough. I want to use the existing API - but I can’t really plug a wraparound primitive into it. While byte in an int works fine (if you tweak the color model to only use 8 low order bits) an unsigned int might be a problem. There are no API’s which work with long types, so int cannot be wrapped into a higher order primitive this way.

So, I might need to check for these things and normalize the data somehow. Now, the big question is - should a negative int be converted to the min or the max value? I guess it is relative…

Seriously though - is there a reason for leaving out unsigned primitives? Any reason at all? Or was this done on a whim?

I still like java, I’m just slightly irritated P

Tags: , , , , , , , , , , , , , , , , ,

Related Posts:

  • Learning Ruby (Part 1)
  • Ruby

  • Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <pre lang=""> <em> <i> <strike> <strong>

    [Quote selected]