Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java package naming legal syntax rules

Tags:

java

Note that I'm not asking about Java package naming conventions.

For example, Java does not legally allow package names to start with a number.

However, the official Java docs doesn't seem to cover the actual rules governing what can or can't be used in a package name.

What are the set of legal package names?

like image 691
Him Avatar asked Feb 25 '26 07:02

Him


1 Answers

It is a Java identifier, followed by N (periods+identifier)s.

PackageDeclaration:
{PackageModifier} package Identifier {. Identifier} ;

https://docs.oracle.com/javase/specs/jls/se16/html/jls-7.html#jls-7.4

An identifier is (incl. some nested definitions):

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"

A "Java letter" is a character for which the method Character.isJavaIdentifierStart(int) returns true.

A "Java letter-or-digit" is a character for which the method Character.isJavaIdentifierPart(int) returns true.

https://docs.oracle.com/javase/specs/jls/se16/html/jls-3.html#jls-Identifier

like image 148
Michael Avatar answered Feb 27 '26 21:02

Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!