Skip to content

Eclipse Java – invalid package name – Reserved words in package name

I am in the middle of an android project and was trying to create a new package in it.

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;

  1. Is this an Eclipse thing? or a Java thing? I tried a pure Java project (not Android), just to check, but there also I got the same error.
  2. What are other reserved words that is not allowed?
  3. Is there any documentation about this?



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:

4 People found this is helpful