Click here to Skip to main content
13,299,727 members (57,496 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I want to use unsigned int in java, how can i use?
Posted 1-Oct-12 11:11am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Java has not unsigned int. Depending of your needs you may find some workarounds "What is the Java equivalent of unsigned?" page[^].
Good catch! And good article to get the explanations as well. My 5.
I personally think that not having some types like uint (not via "unsigned" keyword, of course) is a shame. Unsigned types are heavily under-used, even though they are very important, useful and simple.
CPallini 1-Oct-12 16:46pm
Thank you. Recently I read some criticism of unsigned datatypes (because they are often misused, etc..), unfortunately I have no link.
You are welcome. Good answer anyway.
Criticism? Aha, "because it's hard to understand the difference"? or "hard to predict how a variable will be used"? or "because -1 can be used as "not found""? :-)
Or something a bit more serious, which I cannot believe could be there? Would be interesting to see though... :-)
pasztorpisti 1-Oct-12 17:43pm
You are right, enough time spent in the industry shows you when to use int or uint. But be careful, not every piece of library is written by an architect! :-) Sometimes there is not other choice then using a shamefully bad library written by some clowns to access a service. ;-) When its about integration with legacy stuff I think unsigned types are necessary sometimes, but java showed me that you can leave without uints pretty well if the sorrounding libraries are built without uint.
Good points, appreciate them. And I even have a pretty good idea where those clowns come from; I saw more their dances with the tambourine (or, were they shamans? no matter :-) than I would like to see. :-)
pasztorpisti 1-Oct-12 18:42pm
:-) :-) :-) I think you must have already discovered the following miracle in the industry: programmer with negative (work)force - the sith lords of our mastery. Its most dangerous form is the friend of the principal's son or something like that and fills in a responsible position. Fortunately they mostly avoid smaller companies where their underproductivity could not hide in the dark... Should I continue? :-)
Fortunately, I never faced such people in any really serious positions, neither in small not in big companies. I worked in the companies where a lot of relatives worked, including the relatives of the owner, but... believe or not, they all behaved adequately, at least in terms of their expertize. As I result, I don't see a problem in having relatives at work. I often heard about such nasty situations you mentioned, but never saw such things at my work.

Nevertheless, I saw enough of shear destructive opposition to my work, from other kind of people. Main problem is their knowledge and understanding. You probably know that most illiterate people are the most aggressive (worse, in a hidden way). Perhaps this is the natural compensation for their feel of inadequate expertize in some cases and huge delusion in others (which causes "you fools don't understand my genies idea" attitude)...
pasztorpisti 1-Oct-12 17:34pm
I myself had problem with the unsignedness of java *ONLY* when I had to work with binary data produced by legacy apps (like Solaris audit trail log). Signed types are indeed enough for the majority of problems especially if int64 is natively supported. Without clear reasons I always use signed in C/C++/C# apps too. Having both signed and unsigned types usually introduces a lot of dangerous signed <-> unsigned casts in C/C++ apps especially when the integral types are not your choice but they come from 3rd party libraries when you wire them together. In that case you have no other choice then converting, I think this is very evil in many languages.
Just searched for an article that lists the main points about this topic:
Again, the point is taken, but the unsigned types help to deal with the situations where the negatives make no sense conceptually, and they also allow to pack more significant bits in some short types where the memory utilization could be a considerable factor -- remember the embedded, and not only.

As to the danger of the unsigned -- it's quite real, but good understanding of the issue overcomes it. It's more important to avoid accidental bugs, and we won't let conceptual ones to sneak in :-)
pasztorpisti 1-Oct-12 18:47pm
Sure, it really does not worth the time to write bugs into a program. :-)
Ehe-eehh... well... you understand. :-)
pasztorpisti 1-Oct-12 17:44pm
BTW, +5
Espen Harlinn 1-Oct-12 18:22pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171207.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100