1. ## 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:

Java 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.

2. ## Re: Primitive Data Types

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:

Java 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.

Java 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

3. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,842
Rep Power
10

## 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
Last edited by jim829; 05-08-2013 at 08:43 PM. Reason: slow draw McGraw

4. ## Re: Primitive Data Types

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)

5. ## Re: Primitive Data Types

Originally Posted by JosAH

Java 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
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 )

6. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,842
Rep Power
10

## 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
Last edited by jim829; 05-08-2013 at 10:35 PM.

7. ## Re: Primitive Data Types

Makes sense. Thank you, Jim.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•