This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Missing Numeric Suffixes" Watch "Missing Numeric Suffixes" New topic
Author

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.

Thanks,
Josh


Rational Pi Blog - Java, SCJP, Dev Bits- http://rationalpi.wordpress.com
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.
 
 
subject: Missing Numeric Suffixes
 
Similar Threads
primitives question
wrapper classes
can i assign long var to float?
int as expression value
conversion of primitives