# Primitive Data Types

• 05-08-2013, 08:07 PM
CuppaCoffee
Primitive Data Types
This is literally a one-sentence question. Java's tutorial says the long has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). However, when I declare this:

Code:

`long number = 600851475143;`
I get an error saying "The literal 600851475143 of type int is out of range". So what's going on? Am I missing something here? Did Java lie to me?! :@: (most likely I'm missing something.. Java never lies). Help greatly appreciated.
• 05-08-2013, 08:41 PM
JosAH
Re: Primitive Data Types
Quote:

Originally Posted by CuppaCoffee
This is literally a one-sentence question. Java's tutorial says the long has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive). However, when I declare this:

Code:

`long number = 600851475143;`
I get an error saying "The literal 600851475143 of type int is out of range". So what's going on? Am I missing something here? Did Java lie to me?! :@: (most likely I'm missing something.. Java never lies). Help greatly appreciated.

Code:

`long number = 600851475143L;`
Literal integer numbers are assumed to be ints by default by the compiler, until you tell it otherwise.

kind regards,

Jos
• 05-08-2013, 08:42 PM
jim829
Re: Primitive Data Types
Just like it said, the literal is out of range for an "int." To assign the value of a long, append an L to the end of it.

Regards,
Jim
• 05-08-2013, 08:48 PM
JosAH
Re: Primitive Data Types
Quote:

Originally Posted by jim829
Last edited by jim829; Today at 08:43 PM. Reason: slow draw McGraw

I love this so much; I thought it is worthwhile to repeat it here ;-)

kind regards,

Jos (<--- speedy)
• 05-08-2013, 10:00 PM
CuppaCoffee
Re: Primitive Data Types
Quote:

Originally Posted by JosAH

Code:

`long number = 600851475143L;`
Literal integer numbers are assumed to be ints by default by the compiler, until you tell it otherwise.

kind regards,

Jos

Quote:

Originally Posted by jim829
Just like it said, the literal is out of range for an "int." To assign the value of a long, append an L to the end of it.

Regards,
Jim

Aaaahhhh, I see... What does the 'L' represent though? I've also seen the letter 'f' or 'F' being added to the end and in the middle of numerical variables...

Well, thanks for the assistance, guys! (regardless of the speed :(giggle):)
• 05-08-2013, 10:29 PM
jim829
Re: Primitive Data Types
L is for long, F is for float. Without them, the values are taken to be bytes, shorts, and ints and doubles.

Regards,
Jim
• 05-08-2013, 10:49 PM
CuppaCoffee
Re: Primitive Data Types
Makes sense. Thank you, Jim. :)-: