Commit be360f0
committed
feat: Add Literal1 class demonstrating long literal with suffix
WHAT the code does:
- Defines a `Literal1` class with a `main()` method.
- Declares a `long` variable `L` with value `999999999999L`.
- Prints the value to the console.
WHY this matters:
- Demonstrates how to define **long literals** in Java.
- By default, numeric literals are treated as `int`.
→ The suffix `L` (or `l`) tells the compiler to treat it as a `long`.
- Important when dealing with values larger than the `int` range (±2,147,483,647).
HOW it works:
1. `999999999999` exceeds `int` range.
2. Adding `L` ensures the literal is compiled as a `long`.
3. Program prints `999999999999`.
Tips & gotchas:
- Always use uppercase `L` instead of lowercase `l` to avoid confusion with `1`.
- If the literal fits within `int` range, suffix `L` is optional.
- For very large numbers, consider `BigInteger`.
Use-cases:
- Handling large numbers in financial or scientific calculations.
- Educational demo for **numeric literal suffixes** in Java.
- Ensures clarity when working with values beyond `int`.
Short key: class-literal1-long-literal.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent eb6b369 commit be360f0
1 file changed
+1
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
0 commit comments