Valid characters in a Java class name

Zach picture Zach · Sep 15, 2008 · Viewed 145.9k times · Source

What characters are valid in a Java class name? What other rules govern Java class names (for instance, Java class names cannot begin with a number)?

Answer

Jason Cohen picture Jason Cohen · Sep 15, 2008

You can have almost any character, including most Unicode characters! The exact definition is in the Java Language Specification under section 3.8: Identifiers.

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

Letters and digits may be drawn from the entire Unicode character set, ... This allows programmers to use identifiers in their programs that are written in their native languages.

An identifier cannot have the same spelling (Unicode character sequence) as a keyword (§3.9), boolean literal (§3.10.3), or the null literal (§3.10.7), or a compile-time error occurs.

However, see this question for whether or not you should do that.