I am in the middle of an android project and was trying to create a new package in it.
com.mycompany.myprojectname.new
Well, Eclipse is not letting me to create it and is showing this error:
Invalid package name. 'new' is not a valid Java identifier
I never knew package name has reserved words, which we cannot use. My questions are;
The packages for the open-source Eclipse project are all subpackages of org. eclipse. The first package name segment after org. eclipse is generally the project name, followed by the component name.
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 .
You are right, the simple answer is: You are NOT allowed to use the hypen in package names. If you have a unique package name build from a domainname containing a hyphen you have to translate it to the underscore. Reading all this stuff, this somehow feels outdated.
Package names are all lowercase, with consecutive words simply concatenated together (no underscores). For example, com. example.
Yes, this is a general Java thing.
The list of reserved words can be found here. They are:
abstract continue for new switch assert default goto package synchronized boolean do if private this break double implements protected throw byte else import public throws case enum instanceof return transient catch extends int short try char final interface static void class finally long strictfp volatile const float native super while
Documentation on the fact that reserved words can not be used in package names if found in the package naming tutorial, among other places.
The authoritative source is (as always) the Java Language Specification, specifically:
§ 3.8 Identifiers
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.
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