Course contentsShow
← Java
Lesson 29 of 2,8702. Variables and Primitive TypesFree lesson

The L Suffix for long Literals

Learn why long literals require the L or l suffix to distinguish them from int literals, and best practices for L.

The L Suffix for long Literals

What you'll learn: How to write long numbers correctly so Java doesn't confuse them with int values.


Why the L Suffix Exists

When you write a whole number in Java—like 42 or 1000—the compiler assumes it's an int by default. This works fine for most numbers, but remember that int can only hold values up to about 2.1 billion.

If you want to create a long literal (a number written directly in your code that should be treated as long), you must add an L or l suffix to tell Java: "Hey, this is a long, not an int!"

Without the suffix, even if you're assigning to a long variable, Java first treats the literal as an int. If that number is too big for int, you'll get a compilation error.


How to Use the L Suffix

long smallNumber = 100;        // OK: 100 fits in int, auto-converted to long
long bigNumber = 3000000000;   // ERROR: too big for int!
long bigNumber = 3000000000L;  // OK: the L makes it a long literal

Best Practice: Use Uppercase L

Both L and l work, but always use uppercase L. Why? The lowercase l looks identical to the digit 1 in many fonts:

long confusing = 100l;   // Is that "one-zero-zero-ell" or "one-zero-zero-one"?
long clear = 100L;       // Obviously "one hundred L"

Analogy: It's like writing a note that says "I need 1 liter" vs "I need l liter"—the second is confusing because lowercase L and the number 1 look the same!


Key Takeaway: Use the uppercase L suffix on any long literal that's outside int range or when you want to be explicit that it's a long, not an int.