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.
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. Save this answer.
To clarify, you can name your app 1abcxyz, it's only the package name that cannot start with a digit (you could use oneabcxyz instead of 1abcxyz for example). Having a package name different from your company's website should not influence communications between your app and your company's servers.
Package names are written in all lower case to avoid conflict with the names of classes or interfaces. Companies use their reversed Internet domain name to begin their package names—for example, com. example. mypackage for a package named mypackage created by a programmer at example.com .
While using hyphens in the names of repository items is a recommended practice in AEM development, hyphens are illegal within Java package names.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With