package

The keyword "package" is used at the beginning of a source file to specify a package of given class or interface. For example, if we want to create a class "com.example.animal.Kitten", we create a file "Kitten.java" in a directory "com/example/animal", and start it like this:

package com.example.animal;

public class Kitten {

  // ...

}

Class java.lang.Package

Class "Package" can be used to get some properties of the package. For example:

Object o = new Kitten();
Package p = o.getClass().getPackage();
System.out.println("This object was in package: " + p.getName());

viliam@bur.sk