This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
when specifying numbers, you can append an 'f' for floats, 'd' for doubles, 'l' for longs, but I wonder, why isn't there any such thing for byte and short? Because Java then assumes int, you can't make use of autoboxing when a method or constructor has a java.lang.Byte or java.lang.Short in its param list. Instead you have to code something like new Short((short)12345) instead of just 12345s, for example.
this is my own thinking donot know how much i am correct.
Lets see what experts say.
If we do
Byte b=12; then compiler takes 128 as byte not as int.
try to assign a value 129 to a byte.see you will get compile time error.saying cannot convert from int to byte.
In java implicitly.every primitive(byte,short,int,Long) other than decimal values are treated as integer if within the range of integer
Ranges are defined for example for byte it is -128 to +127.
anything outside the range of byte will be treaded as integer.
and also if we do
short s=-32,768 to 32,767.
then everything outside this range and within the integer range( -2147483648 to 2147483647)will be considered as integer
mentioning long with "L" is mandatory because if we donot mention it compiler takes it
as integer and as long range is more as compare to integer
for float and double(like int above here it is double)
but in the case of float and double
if we donot mention "F" if
then compiler assumes the precision type as double as sees that it is not
within the range float as mentioned so gives compile time error.
so it is mandatory to mention it as "f" after the float value.
even in case of method overloading we call any method
using byte value
doStuff(100); this will first search for byte value if not found then only widening will happen otherwise not.