my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Minimum and maximum  useable values for int long Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Minimum and maximum  useable values for int long" Watch "Minimum and maximum  useable values for int long" New topic
Author

Minimum and maximum useable values for int long

Simon Evans
Ranch Hand

Joined: Mar 27, 2008
Posts: 93
Dear Programmers,

In the text I have read, it states that for an integer type long, the biggest value it can be given is:-
9223372036854775807;
and the smallest value it can be given is:-
-9223372036854775808;
however in the following program:-

both initialisations return a compiler error - that bigLong is too big and the smallLong is too big : -


How is this? Is it rectifiable?

Hope you can help.

Yours

Simon


Simon
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18760
    
  40

Literals are by default ints -- not longs. So, it is complaining that the literal is too big for an int, not that it is too big to be assigned to a long.

To have long literals, use an "L" suffix.

long l = 123456L;

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Simon Evans
Ranch Hand

Joined: Mar 27, 2008
Posts: 93
Dear Henry Wong,
Your are right, it runs okay now - thank you for your advice.
Yours
Simon
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38481
    
  23
There are similar problems with floats, which may require an "f" suffix, and you can suffix "d" to doubles. This is one of the few places where Java is case-insensitive, but always use a capital L, not a small l; I hope the reasons will be obvious.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Minimum and maximum useable values for int long