Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Comparison of C Sharp and Java
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===== Unsigned integers ===== C# supports [[signedness|unsigned]] in addition to the [[signedness|signed]] integer types. The unsigned types are {{mono|byte}}, {{mono|ushort}}, {{mono|uint}} and {{mono|ulong}} for 8, 16, 32 and 64 bit widths, respectively. Unsigned arithmetic operating on the types are supported as well. For example, adding two unsigned integers ({{mono|uint}}s) still yields a {{mono|uint}} as a result; not a long or signed integer. Java does not feature unsigned integer types. In particular, Java lacks a primitive type for an unsigned [[byte]]. Instead, Java's {{mono|byte}} type is [[sign extension|sign extended]], which is a common source of bugs and confusion.<ref>{{cite book |title=Java puzzlers : traps, pitfalls, and corner cases|year=2005 |publisher=Addison-Wesley|location=Upper Saddle River, NJ [u.a.]|isbn=978-0-321-33678-1|author=Joshua Bloch; Neal Gafter|edition=5. print.|page=36|quote=The lesson for language designers is that sign extension of byte values is a common source of bugs and confusion. The masking that is required to suppress sign extension clutters programs, making them less readable. Therefore, the byte type should be unsigned.}}<!-- |access-date=6 October 2012--></ref> Unsigned integers were left out of Java deliberately because [[James Gosling]] believed that programmers would not understand how unsigned arithmetic works.<blockquote>In programming language design, one of the standard problems is that the language grows so complex that nobody can understand it. One of the little experiments I tried was asking people about the rules for unsigned arithmetic in C. It turns out nobody understands how unsigned arithmetic in C works. There are a few obvious things that people understand, but many people don't understand it.<ref name="oracle.com"/><ref>{{cite web |url=http://www.artima.com/intv/gosling3P.html |title=James Gosling on Java, May 2001 |publisher=Artima.com |date=10 May 2001 |access-date=24 February 2015}}</ref></blockquote> Java versions 8 and 9 added some limited built-in unsigned integer operations, but they are only exposed as static methods on the primitive wrapper classes; they operate on signed primitive integer types, treating them as if they were unsigned.<ref>{{cite web |url=https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html |title=Integer (Java Platform SE 8) |publisher=Docs.oracle.com |access-date=20 Apr 2023}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)