> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Java long

The `long` keyword in Java designates a 64-bit signed two's complement integer primitive data type. It provides a significantly larger numerical range than the standard 32-bit `int` type, allocating 8 bytes of memory per variable.

## Technical Specifications

* **Memory Size:** 64 bits (8 bytes)
* **Minimum Value:** $-2^{63}$ (`-9,223,372,036,854,775,808`), accessible via `Long.MIN_VALUE`
* **Maximum Value:** $2^{63}-1$ (`9,223,372,036,854,775,807`), accessible via `Long.MAX_VALUE`
* **Default Value:** `0L` (when declared as a class or instance variable)
* **Wrapper Class:** `java.lang.Long` (used for generics and utility methods)

## Syntax and Literals

By default, Java interprets unadorned integer literals as `int`. To explicitly define a `long` literal, you must append the suffix `L` or `l` to the number. The uppercase `L` is the universally accepted standard, as the lowercase `l` is visually indistinguishable from the digit `1` in many fonts.

```java theme={"dark"}
// Standard declaration
long defaultLong;

// Initialization with the 'L' suffix
long exactLong = 5000000000L;

// The suffix is strictly required if the literal exceeds the 32-bit int limit (2,147,483,647)
// long invalidLong = 5000000000; // Compilation error: integer number too large

// Java 7+ allows underscores for digit grouping to improve readability
long readableLong = 9_223_372_036_854_775_807L;
```

`long` variables also support alternative base representations:

```java theme={"dark"}
// Hexadecimal literal (prefix 0x)
long hexLong = 0x7FFF_FFFF_FFFF_FFFFL;

// Binary literal (prefix 0b)
long binaryLong = 0b1111_0000_1010_0101L;

// Octal literal (prefix 0)
long octalLong = 0777L;
```

## Type Casting

Because `long` occupies a larger memory footprint than `byte`, `short`, or `int`, Java performs implicit widening conversions. Conversely, converting a `long` down to a smaller integer type requires an explicit narrowing cast, which truncates the upper 32 bits and may result in data loss or sign inversion.

```java theme={"dark"}
// Implicit Widening (int -> long)
int standardInt = 1024;
long widenedLong = standardInt; 

// Explicit Narrowing (long -> int)
long massiveLong = 3_000_000_000L;
int narrowedInt = (int) massiveLong; // Results in -1294967296 due to bit truncation
```

## Concurrency and Atomicity

In the Java Memory Model (JMM), read and write operations on 64-bit `long` primitives are not guaranteed to be atomic on 32-bit architectures. The JVM may execute a 64-bit operation as two separate 32-bit operations, potentially exposing a partially updated state (word tearing) to other threads.

To guarantee atomic reads and writes across all architectures, a `long` must be declared with the `volatile` modifier, or managed via the `java.util.concurrent.atomic.AtomicLong` class.

```java theme={"dark"}
// Guarantees atomic read/write operations in a multithreaded environment
private volatile long threadSafeLong;
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Java Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
