aspose file tools*
The moose likes Beginning Java and the fly likes 64 bit long ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "64 bit long ??" Watch "64 bit long ??" New topic
Author

64 bit long ??

Dean Jones
Greenhorn

Joined: Sep 12, 2003
Posts: 3
So, I was trying to do a for loop earlier like this:

and I kept getting: integer number too large
and I realized something... How the heck can a long be 64 bits on a 32 bit machine?? I mean, in every Java book I have been reading, I haven't noticed them state anything about that. If they have, I must of skimmed over it... Which is HIGHLY possible.
However, I am curious... Is the long a pseudo 64 bit integer somehow? Or am I right in thinking that if I'm sitting on a 32 bit Intel machine, then the long can only be 32 bits and hence my compiler error?
Thanks!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi Dean,
Welcome to JavaRanch!
First, the syntax error: you have to write "long" constants as 50000000000000L -- that trailing "L" means it's a long, not an int.
Now, how can longs be 64 bits? The JVM specification explains that they take up two 32-bit slots on the JVM stack, or two adjacent 32-bit registers. This has some interesting consequences: for example, reading or writing to long values is not "atomic" with respect to multithreading. You have to be careful with longs or you can accidentally "see" partially-written values.
In a "real" 32-bit computer, it works much the same way (although there aren't rigid stack "slots", the registers are indeed a fixed 32 bits.) There are usually special CPU instructions that operate on longs; the register-based versions assume that multiple registers are being used to hold the value. The threading issues naturally fall out of this architecture.


[Jess in Action][AskingGoodQuestions]
Dean Jones
Greenhorn

Joined: Sep 12, 2003
Posts: 3
I think the trailing L and F are going to end up being the death of me in Java... Thanks for your help.
Joe Pluta
Ranch Hand

Joined: Jun 23, 2003
Posts: 1376
For me it was the fact that a leading zero made things octal. Ugh.
Joe
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 64 bit long ??