File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Missing Numeric Suffixes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Missing Numeric Suffixes" Watch "Missing Numeric Suffixes" New topic

Missing Numeric Suffixes

Joshua Smith
Ranch Hand

Joined: Aug 22, 2005
Posts: 193
Why aren't there numeric suffices for byte, short or int? By numeric suffices I mean the letters that you attach to a number to coerce it into being a specific type of primitive literal (e.g. 2L to mean "2 as a long"). The lack of a numeric suffix for int kind of make sense as int is the default for integral numbers, but then consistency would seem to indicate that there wouldn't be one for double since double is the default for floating point literals. And why would byte and short be left out?

I'm not sure how important the answer to this question is to certification, but I'm wondering if there's something about the numeric primitives that I'm missing that would make the answer obvious.


Rational Pi Blog - Java, SCJP, Dev Bits-
Thomas Paul Bigbee
Ranch Hand

Joined: Jun 28, 2005
Posts: 71
Its because floating point literals (0.1, 122.32, etc...) are automatically considered as doubles, so float x = 0.1 would cause a compile time error, where as with bytes, shorts, chars, ints and longs, this would work with all of them - byte x = 1, short x = 1, etc..., its just the way the spec was written.
I agree. Here's the link:
subject: Missing Numeric Suffixes
jQuery in Action, 3rd edition