---
spec: JVMS
title: "The Java Virtual Machine Specification"
edition: "Java SE 18 Edition"
java_version: 18
chapter: "Chapter 4. The class File Format"
section: "4.7.27"
heading: "4.7.27. The ModuleMainClass Attribute"
parent: "4.7. Attributes"
source: https://docs.oracle.com/javase/specs/jvms/se18/html/jvms-4.html#jvms-4.7.27
id: "4.7.27"
url: https://jvm.obfuscated.software/jvms/se18/4.7.27.html
raw: https://jvm.obfuscated.software/jvms/se18/4.7.27.md
---

# 4.7.27. The `ModuleMainClass` Attribute

The `ModuleMainClass` attribute is a fixed-length attribute in the `attributes` table of a `ClassFile` structure ([§4.1](4.1.md). The `ModuleMainClass` attribute indicates the main class of a module.

There may be at most one `ModuleMainClass` attribute in the `attributes` table of a `ClassFile` structure.

The `ModuleMainClass` attribute has the following format:

```
ModuleMainClass_attribute {
    u2 attribute_name_index;
    u4 attribute_length;
    u2 main_class_index;
}
```

The items of the `ModuleMainClass_attribute` structure are as follows:

- **attribute_name_index**

  The value of the `attribute_name_index` item must be a valid index into the `constant_pool` table. The `constant_pool` entry at that index must be a `CONSTANT_Utf8_info` structure ([§4.4.7](4.4.7.md)) representing the string "`ModuleMainClass`".

- **attribute_length**

  The value of the `attribute_length` item must be two.

- **main_class_index**

  The value of the `main_class_index` item must be a valid index into the `constant_pool` table. The `constant_pool` entry at that index must be a `CONSTANT_Class_info` structure ([§4.4.1](4.4.1.md)) representing the main class of the current module.
