Lesson: Packages and Imports

Introduction to packages and the import statement.

Gain a basic understanding of packages and the import statement.


Classes within a project or in a library are organized into packages. A package is simply a grouping identifier specified at the top of a class with the package statement. In a project, all classes with the same package name are grouped together under that name. Packages are important when we want to use libraries of classes published by other programmers, such as the Java Class Library or one of the robot specific libraries included in robot SDKs. Packages resolve naming conflicts between classes and help programmers to locate the classes they would like to use in their programs.

So how do we make use of packages? If we want to use an external class in our program, we tell Java which package contains the class we want to use with the import statement. Placed at the top of our program, one or more import statements make the imported classes act like they are part of our program and we can then work with those classes in our code.

You will see various package and import statements in the examples. Packages and importing them are discussed in more detail in Unit 13.