This week's book giveaways are in the iOS and Features new in Java 8 forums. We're giving away four copies each of Barcodes with iOS: Bringing together the digital and physical worlds and Core Java for the Impatient and have the authors on-line! See this thread and this one for details.
I didnt understand. Is there not any difference between
long long1 = 123456789l; // lowercase l at the end long long2 = 123456789L; // uppercase L at the end
Is readability is the only difference between those two?
Joined: Jan 30, 2000
The only difference is that the first one is Evil, and the second is Good.
Yes, readability is the only difference. But it's a pretty important difference, I think. In many fonts, it's extremely difficult to tell the difference between a l and a 1 - so it's vital to make this distinction clear whenever possible. Since Java allows l or L to indicate a long literal, using L makes things very clear, while using l does not.
Originally posted by Santhosh Kumar: That is because, all numeric literal are integers by default in Java. If you want JVM to consider that numeric literal as long, you need to be explicit about it.
Say it as (note the small l at the end, which says, my literal is long)
long l = 2342444324324423l;
i m strongly aganinst this statement...because as i didn't heard about this anywhere can you show me where its written in K&B and i wanted to say that
if it is integer...then it must be automatcially cast to long as int->long implicitly castable and in above original post the left side declaration is already long so there should not be any problem ...
pls correct me ..i m much confused and if possible give me the link where its written or copy past from K&B ebook
Thanks and Regards, Amit Taneja
Joined: Jan 30, 2000
[amit]: i m strongly aganinst this statement...because as i didn't heard about this anywhere
I think you should have a better reason than this if you want to be "strongly against" anything. Santhosh provided actual code - did you try to compile it and run it? It's a great way to learn new things.
seriously not heard about this thing anywhere... can anybody pls tell me or copy past K&B text...or
tell me why its soo occouring
why dont it is not getting implicitly cast to long ???
it should be atleast implicitly casted.....
i have heard about that foat literals are by default double...
but not about this.....
Joined: May 24, 2005
For implicitly getting typecasted, that literal should be a valid integer. Here, the literal is too big to be treated as an integer literal. Above, 2147483650 is exceeding the range of the int (32 bits).