---
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.5"
heading: "4.12.5. Initial Values of Variables"
parent: "4.12. Variables"
source: https://docs.oracle.com/javase/specs/jls/se26/html/jls-4.html#jls-4.12.5
id: "4.12.5"
url: https://jvm.obfuscated.software/jls/se26/4.12.5.html
raw: https://jvm.obfuscated.software/jls/se26/4.12.5.md
---

# 4.12.5. Initial Values of Variables

Every variable in a program must have a value before its value is used:

- Each class variable, instance variable, or array component is initialized with a *default value* when it is created ([§15.9](15.9.md), [§15.10.2](15.10.2.md)):

  - For type `byte`, the default value is zero, that is, the value of `(byte)0`.
  - For type `short`, the default value is zero, that is, the value of `(short)0`.
  - For type `int`, the default value is zero, that is, `0`.
  - For type `long`, the default value is zero, that is, `0L`.
  - For type `float`, the default value is positive zero, that is, `0.0f`.
  - For type `double`, the default value is positive zero, that is, `0.0d`.
  - For type `char`, the default value is the null character, that is, `'\u0000'`.
  - For type `boolean`, the default value is `false`.
  - For all reference types ([§4.3](4.3.md)), the default value is `null`.

- Each method parameter ([§8.4.1](8.4.1.md)) is initialized to the corresponding argument value provided by the invoker of the method ([§15.12](15.12.md)).

- Each constructor parameter ([§8.8.1](8.8.1.md)) is initialized to the corresponding argument value provided by a class instance creation expression ([§15.9](15.9.md)) or constructor invocation ([§8.8.7](8.8.7.md)).

- An exception parameter ([§14.20](14.20.md)) is initialized to the thrown object representing the exception ([§11.3](11.3.md), [§14.18](14.18.md)).

- A local variable declared by a statement ([§14.4.2](14.4.2.md), [§14.14.1](14.14.1.md), [§14.14.2](14.14.2.md), [§14.20.3](14.20.3.md)) must be explicitly given a value before it is used, by either initialization ([§14.4](14.4.md)) or assignment ([§15.26](15.26.md)), in a way that can be verified using the rules for definite assignment ([§16 (*Definite Assignment*)](16.md)).

  A local variable declared by a pattern ([§14.30.1](14.30.1.md)) is initialized implicitly, by the process of pattern matching ([§14.30.2](14.30.2.md)).

**Example 4.12.5-1. Initial Values of Variables**

```
class Point {
    static int npoints;
    int x, y;
    Point root;
}

class Test {
    public static void main(String[] args) {
        System.out.println("npoints=" + Point.npoints);
        Point p = new Point();
        System.out.println("p.x=" + p.x + ", p.y=" + p.y);
        System.out.println("p.root=" + p.root);
    }
}
```

This program prints:

```
npoints=0
p.x=0, p.y=0
p.root=null
```

illustrating the default initialization of `npoints`, which occurs when the class `Point` is prepared ([§12.3.2](12.3.2.md)), and the default initialization of `x`, `y`, and `root`, which occurs when a new `Point` is instantiated. See [§12 (*Execution*)](12.md) for a full description of all aspects of loading, linking, and initialization of classes and interfaces, plus a description of the instantiation of classes to make new class instances.
