---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 26 Edition"
java_version: 26
chapter: "Chapter 4. Types, Values, and Variables"
section: "4.12"
heading: "4.12. Variables"
parent: "Chapter 4. Types, Values, and Variables"
source: https://docs.oracle.com/javase/specs/jls/se26/html/jls-4.html#jls-4.12
id: "4.12"
url: https://jvm.obfuscated.software/jls/se26/4.12.html
raw: https://jvm.obfuscated.software/jls/se26/4.12.md
---

# 4.12. Variables

A variable is a storage location and has an associated type, sometimes called its *compile-time type*, that is either a primitive type ([§4.2](4.2.md)) or a reference type ([§4.3](4.3.md)).

A variable's value is changed by an assignment ([§15.26](15.26.md)) or by a prefix or postfix `++` (increment) or `--` (decrement) operator ([§15.14.2](15.14.2.md), [§15.14.3](15.14.3.md), [§15.15.1](15.15.1.md), [§15.15.2](15.15.2.md)).

Compatibility of the value of a variable with its type is guaranteed by the design of the Java programming language, as long as a program does not give rise to compile-time unchecked warnings ([§4.12.2](4.12.2.md)). Default values ([§4.12.5](4.12.5.md)) are compatible and all assignments to a variable are checked for assignment compatibility ([§5.2](5.2.md)), usually at compile time, but, in a single case involving arrays, a run-time check is made ([§10.5](10.5.md)).

**Sections:**

- [4.12.1. Variables of Primitive Type](4.12.1.md)
- [4.12.2. Variables of Reference Type](4.12.2.md)
- [4.12.3. Kinds of Variables](4.12.3.md)
- [4.12.4. final Variables](4.12.4.md)
- [4.12.5. Initial Values of Variables](4.12.5.md)
- [4.12.6. Types, Classes, and Interfaces](4.12.6.md)
