Lesson: Packages and Imports

Overview: 
Introduction to packages and the import statement.
Objectives: 

Gain a basic understanding of packages and the import statement.

Content: 

Classes within a project or in a library are organized into packages. A package is simply an 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. Packages resolve naming conflicts between classes and help programmers to locate the classes they would like to make use of in their programs.

So how do we make use of packages? If we want to use one or more classes in a package in our program, we tell Java which packageĀ (or constituent 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 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 8.

Navigation: