Using numbers as package names in java

I've already checked the following posts:

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 to create 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 the syntactic correctness of the name, not the convention.

Is there an oracle / SUN link that maps the syntax for a package, or follows the same rules as variable names in java? May be a reference in the Java language specification that package names follow the same rules as variable names.

+3


source to share


2 answers


This is a reference to the identifier grammar that Java uses and applies wherever an identifier is specified, including but not limited to the package name. Thus, it is 01

definitely not a valid package name because it is not a valid identifier.



+2


source


Found:

If any of the resulting package name components start with a digit or any other character that is not allowed as the starting identifier character, use the underscore attached to the component.



B Announcements JLS 6.1

+2


source







All Articles