Rules to define a java package statement

Rules to remember when defining a package statement:

  1. There can be EXACTLY ONE package statement in a java source code file.
  2. Package and sub-package names should always be in lowercase (according to Java naming conventions). Their names should follow the rules defined for valid java identifiers.
  3. The package and sub-package names are separated using a dot.
  4. For packaged java types (classes, interfaces, enumerations and annotations) the package statement is the first statement in a java code source file. The ONLY exception is that comments can appear before or after a package statement.

And remember: All the classes and interfaces defined in a java source code file are defined in the same package. (i.e, under no circumstances the classes, interfaces, enumerations and annotations defines in the same Java source code file can be part of a different packages.

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Leave a Reply