Some points to note about packaging :

  1. A package declaration has to be the first line in a java program. All other statements follow the package statement.
  2. If we import a package as import a.b.c.* then all class inside the a/b/c directory would be available in classpath but classes in subpackage below a/b/c/ or a sibling package parallel to a/b/c would not be available. They need to be specifically be imported.
    packageAs an example above , if we import java.util.* only classes in this package i.e. ArrayList.class , Map.class would be imported and classes from other sibling packages like java.lang would not be imported.
  3. If we do not specify any package to a java class then it is assumed to be present in default package. The default package is not any special package but its just a name given to an unnamed package. It is a compilation error if some class present in some xyz package refers to a class in default package because classes in default packages cannot be imported. The statement import *; is invalid. Hence it is best to avoid placing classes in default package.
  4. Naming a package is an important step in writing a java program. The recommended way of naming your package is to use the reverse domain name format. For example if I work for google , whose internet address is google.com , and I write a email feature then my package structure should look like com.google.email. This ensure that package name is unique and distinguish.
  5. We can also use the fully classified name of a class (FQCN) if we wish not to write import statement.  For example to use the String class of java without writing the import statement we can write java.util.String and use it. This specially comes in handy when we have 2 classes with same name but in different package. Here we can import one of the class and use FQCN for the other class.