---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 9 Edition"
java_version: 9
chapter: "Chapter 6. The Java Virtual Machine Instruction Set"
section: "6.5.putstatic"
heading: "putstatic"
parent: "6.5. Instructions"
source: https://docs.oracle.com/javase/specs/jvms/se9/html/jvms-6.html#jvms-6.5.putstatic
id: "6.5.putstatic"
url: https://jvm.obfuscated.software/jvms/se9/6.5.putstatic.html
raw: https://jvm.obfuscated.software/jvms/se9/6.5.putstatic.md
---

# putstatic

## Operation

Set static field in class

## Format

```
putstatic
indexbyte1
indexbyte2
```

## Forms

*putstatic* = 179 (0xb3)

## Operand Stack

..., *value* →

...

## Description

The unsigned *indexbyte1* and *indexbyte2* are used to construct an index into the run-time constant pool of the current class ([§2.6](2.6.md)), where the value of the index is (*indexbyte1* `<<` 8) | *indexbyte2*. The run-time constant pool item at that index must be a symbolic reference to a field ([§5.1](5.1.md)), which gives the name and descriptor of the field as well as a symbolic reference to the class or interface in which the field is to be found. The referenced field is resolved ([§5.4.3.2](5.4.3.2.md)).

On successful resolution of the field, the class or interface that declared the resolved field is initialized if that class or interface has not already been initialized ([§5.5](5.5.md)).

The type of a *value* stored by a *putstatic* instruction must be compatible with the descriptor of the referenced field ([§4.3.2](4.3.2.md)). If the field descriptor type is `boolean`, `byte`, `char`, `short`, or `int`, then the *value* must be an `int`. If the field descriptor type is `float`, `long`, or `double`, then the *value* must be a `float`, `long`, or `double`, respectively. If the field descriptor type is a reference type, then the *value* must be of a type that is assignment compatible (JLS §5.2) with the field descriptor type. If the field is `final`, it must be declared in the current class or interface, and the instruction must occur in the class or interface initialization method of the current class or interface ([§2.9.2](2.9.2.md)).

The *value* is popped from the operand stack.

If the *value* is of type `int` and the field descriptor type is `boolean`, then the `int` *value* is narrowed by taking the bitwise AND of *value* and 1, resulting in *value*'. Otherwise, the *value* undergoes value set conversion ([§2.8.3](2.8.3.md)), resulting in *value*'.

The referenced field in the class or interface is set to *value*'.

## Linking Exceptions

During resolution of the symbolic reference to the class or interface field, any of the exceptions pertaining to field resolution ([§5.4.3.2](5.4.3.2.md)) can be thrown.

Otherwise, if the resolved field is not a `static` (class) field or an interface field, *putstatic* throws an `IncompatibleClassChangeError`.

Otherwise, if the resolved field is `final`, it must be declared in the current class or interface, and the instruction must occur in the class or interface initialization method of the current class or interface. Otherwise, an `IllegalAccessError` is thrown.

## Run-time Exception

Otherwise, if execution of this *putstatic* instruction causes initialization of the referenced class or interface, *putstatic* may throw an `Error` as detailed in [§5.5](5.5.md).

## Notes

A *putstatic* instruction may be used only to set the value of an interface field on the initialization of that field. Interface fields may be assigned to only once, on execution of an interface variable initialization expression when the interface is initialized ([§5.5](5.5.md), JLS §9.3.1).
