File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes integral literal Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "integral literal" Watch "integral literal" New topic
Author

integral literal

John Ryan
Ranch Hand

Joined: Mar 14, 2001
Posts: 124
Hi all,
Just a question regarding integral literals. The Java language specification says that all integral literals are 32 bit values. To indicate a long(64 bit) literal append the suffix L to the literal expression.
Right now i cant see the purpose of this (im sure that theres a really obvious reason that ill just kick myself when i hear). If a integral literal is assigned to a long variable then is this literal not upcast automatically to a long. So why do you need to indicate to the VM using L that the literal is to be a long??
thanks,
john
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
The main reason I can think of is for readability. It indicates that you know what you are talking about. However, I don't ever use this convention. It DOES seem a bit redundant, doesn't it?
The only other thing that comes to mind is that perhaps the compiler can do some kind of optimization if you indicate that the literal is really a long.


Java API Documentation
The Java Tutorial
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
try putting this line into your code and you'll see why you need the L
long myLong = 123123123123123 ;


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
John Ryan
Ranch Hand

Joined: Mar 14, 2001
Posts: 124
Originally posted by Marilyn de Queiroz:
try putting this line into your code and you'll see why you need the L
long myLong = 123123123123123 ;

cheers, now i feel stupid. Had to be somthing obvious
:roll:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: integral literal