11

I have checked the following posts already:

https://docs.oracle.com/javase/specs/jls/se7/html/jls-6.html#jls-6.2

and SO post:

Is this a valid java package name?

and

What package naming convention do you use for personal/hobby projects in Java?

I tried creating a package like this:

package 01;
public class Test
{
// ...
}

When I compile I get this:

I:\code>javac 01\Test.java
01\Test.java:1: error: <identifier> expected
package 01;
       ^
1 error

I am looking for syntactical correctness of the name not the convention.

Is there a oracle/SUN reference that lists out the syntax for a package or does it follow the same rules as for variable names in java? May be a reference in the Java Language Specification saying package names follow the same rules as variable names.

Community
  • 1
  • 1
Ayusman
  • 8,509
  • 21
  • 79
  • 132

2 Answers2

16

Found it:

If any of the resulting package name components start with a digit, or any other character that is not allowed as an initial character of an identifier, have an underscore prefixed to the component.

In JLS 6.1 Declarations

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
14

This links to identifier grammar that Java uses, which applies everywhere identifier is mentioned, including but not limited to package name. So 01 is definitely not a valid package name, since it's not a valid identifier.

LeleDumbo
  • 9,192
  • 4
  • 24
  • 38