---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 16 Edition"
java_version: 16
chapter: "Chapter 6. Names"
section: "6.2"
heading: "6.2. Names and Identifiers"
parent: "Chapter 6. Names"
source: https://docs.oracle.com/javase/specs/jls/se16/html/jls-6.html#jls-6.2
id: "6.2"
url: https://jvm.obfuscated.software/jls/se16/6.2.html
raw: https://jvm.obfuscated.software/jls/se16/6.2.md
---

# 6.2. Names and Identifiers

A *name* is used to refer to an entity declared in a program.

There are two forms of names: simple names and qualified names.

A *simple name* is a single identifier.

A *qualified name* consists of a name, a "`.`" token, and an identifier.

In determining the meaning of a name ([§6.5](6.5.md)), the context in which the name appears is taken into account. The rules of [§6.5](6.5.md) distinguish among contexts where a name must denote (refer to) a package ([§6.5.3](6.5.3.md)); a class, interface, or type parameter ([§6.5.5](6.5.5.md)); a variable or value in an expression ([§6.5.6](6.5.6.md)); or a method ([§6.5.7](6.5.7.md)).

Packages, classes, interfaces, and type parameters have members which may be accessed by qualified names. As background for the discussion of qualified names and the determination of the meaning of names, see the descriptions of membership in [§4.4](4.4.md), [§4.5.2](4.5.2.md), [§4.8](4.8.md), [§4.9](4.9.md), [§7.1](7.1.md), [§8.2](8.2.md), [§9.2](9.2.md), and [§10.7](10.7.md).

Not all identifiers in a program are a part of a name. Identifiers are also used in the following situations:

- In declarations ([§6.1](6.1.md)), where an identifier may occur to specify the name by which the declared entity will be known.

- As labels in labeled statements ([§14.7](14.7.md)) and in `break` and `continue` statements ([§14.15](14.15.md), [§14.16](14.16.md)) that refer to statement labels.

  The identifiers used in labeled statements and their associated `break` and `continue` statements are completely separate from those used in declarations.

- In field access expressions ([§15.11](15.11.md)), where an identifier occurs after a "`.`" token to indicate a member of the object denoted by the expression before the "`.`" token, or the object denoted by the `super` or *TypeName*`.super` before the "`.`" token.

- In some method invocation expressions ([§15.12](15.12.md)), wherever an identifier occurs after a "`.`" token and before a "`(`" token to indicate a method to be invoked for the object denoted by the expression before the "`.`" token, or the type denoted by the *TypeName* before the "`.`" token, or the object denoted by the `super` or *TypeName*`.super` before the "`.`" token.

- In some method reference expressions ([§15.13](15.13.md)), wherever an identifier occurs after a "`::`" token to indicate a method of the object denoted by the expression before the "`::`" token, or the type denoted by the *TypeName* before the "`::`" token, or the object denoted by the `super` or *TypeName*`.super` before the "`::`" token.

- In qualified class instance creation expressions ([§15.9](15.9.md)), where an identifier occurs to the right of the `new` token to indicate a type that is a member of the compile-time type of the expression preceding the `new` token.

- In element-value pairs of annotations ([§9.7.1](9.7.1.md)), to denote an element of the corresponding annotation interface.

In this program:

```
class Test {
    public static void main(String[] args) {
        Class c = System.out.getClass();
        System.out.println(c.toString().length() +
                           args[0].length() + args.length);
    }
}
```

the identifiers `Test`, `main`, and the first occurrences of `args` and `c` are not names. Rather, they are identifiers used in declarations to specify the names of the declared entities. The names `String`, `Class`, `System.out.getClass`, `System.out.println`, `c.toString`, `args`, and `args.length` appear in the example.

The occurrence of `length` in `args.length` is a name because `args.length` is a qualified name ([§6.5.6.2](6.5.6.2.md)) and not a field access expression ([§15.11](15.11.md)). A field access expression, as well as a method invocation expression, a method reference expression, and a qualified class instance creation expression, uses an identifier rather than a name to denote the member of interest. Thus, the occurrence of `length` in `args[0].length()` is *not* a name, but rather an identifier appearing in a method invocation expression.

One might wonder why these kinds of expression use an identifier rather than a simple name, which is after all just an identifier. The reason is that a simple expression name is defined in terms of the lexical environment; that is, a simple expression name must be in the scope of a variable declaration ([§6.5.6.1](6.5.6.1.md)). On the other hand, field access, qualified method invocation, method references, and qualified class instance creation all refer to members whose names are not in the lexical environment. By definition, such names are bound only in the context provided by the *Primary* of the field access expression, method invocation expression, method reference expression, or class instance creation expression; or by the `super` of the field access expression, method invocation expression, or method reference expression; and so on. Thus, we denote such members with identifiers rather than simple names.

To complicate things further, a field access expression is not the only way to denote a field of an object. For parsing reasons, a qualified name is used to denote a field of an in-scope variable. (The variable itself is denoted with a simple name, alluded to above.) It is necessary for access control ([§6.6](6.6.md)) to apply to both denotations of a field.
