Is main a valid Java identifier?

public class J {
    public static void main(String[] args)
    {
        String main = "The character sequence \"main\" is an identifier, not a keyword or reserved word.";
        System.out.println(main);
    }
}

This compiles, and when executed, emits this output:

The character sequence "main" is an identifier, not a keyword or reserved word.

The character sequence main is an identifier, not a keyword or reserved word.

The relevant section of the JLS is 3.8:

An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.

Identifier:

    IdentifierChars but not a Keyword or BooleanLiteral or NullLiteral

IdentifierChars:

    JavaLetter {JavaLetterOrDigit}

JavaLetter:

    any Unicode character that is a “Java letter”

JavaLetterOrDigit:

    any Unicode character that is a “Java letter-or-digit”

The character sequence main fits the above description and is not in the keyword list in Section 3.9.

(The character sequence java1234 is also an identifier, for the same reasons.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)