Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java
I want to use unsigned int in java, how can i use?
Posted 1-Oct-12 10:11am
Rate this: bad
good
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[^].
  Permalink  
v2
Comments
Sergey Alexandrovich Kryukov at 1-Oct-12 16:29pm
   
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. --SA
CPallini at 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.
Sergey Alexandrovich Kryukov at 1-Oct-12 17:20pm
   
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... :-) --SA
pasztorpisti at 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.
Sergey Alexandrovich Kryukov at 1-Oct-12 18:28pm
   
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. :-) --SA
pasztorpisti at 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? :-)
Sergey Alexandrovich Kryukov at 1-Oct-12 18:55pm
   
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)... --SA
pasztorpisti at 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: http://critical.eschertech.com/2010/04/07/danger-unsigned-types-used-here/
Sergey Alexandrovich Kryukov at 1-Oct-12 18:31pm
   
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 :-) --SA
pasztorpisti at 1-Oct-12 18:47pm
   
Sure, it really does not worth the time to write bugs into a program. :-)
Sergey Alexandrovich Kryukov at 1-Oct-12 19:09pm
   
Ehe-eehh... well... you understand. :-) --SA
pasztorpisti at 1-Oct-12 17:44pm
   
BTW, +5
Espen Harlinn at 1-Oct-12 18:22pm
   
5'ed!

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Guruprasad.K.Basavaraju 490
1 Sergey Alexandrovich Kryukov 316
2 Shai Vashdi 264
3 OriginalGriff 250
4 praveen_07 115
0 Sergey Alexandrovich Kryukov 9,185
1 OriginalGriff 5,315
2 Peter Leow 4,040
3 Maciej Los 3,535
4 Abhinav S 3,308


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid