Java Packages


Java provides a wide range of classes for use in projects, called the Java API or the Java platform. These classes are provided as a set of packages that can be used in any Java source file. Java Lab supports a subset of the Java API and also offers a set of packages for Neighborhood and Theater projects.

By default, a version of the  java.lang package is automatically available for use in any Java source file. This package includes the System class, which allows for sending and receiving text to the console, as well as math functions in the Math class and several classes for working with strings, numbers, and objects. For security reasons, the full java.lang package is not available in Java Lab. Students will receive an error if they attempt to explicitly import the java.lang package.

Importing Packages

There are several other packages available for use that must be imported to a source file using the import keyword. For example, to use Java’s built-in File class for reading and writing files, you need to write the following at the top of a source file:

import java.util.File;

If you wish to import all classes provided by a package, you can use a the * symbol to means “all classes”:

import java.util.*;

Java Lab does not support the full list of Java packages that would be available in many other Java environments. At this time, Java Lab supports a subset of classes in the java.util, java.lang, and packages. Please refer to the Java Lab documentation for a full list of available packages and classes. Packages provides several packages to enable interaction and drawing in Java Lab. All packages begin with org.code, such as org.code.neighborhood which includes the Painter class used to paint in the Neighborhood. Note that the org.code.neighborhood package is only available in Neighborhood levels, and the package is only available in Theater levels. More info about these packages and more can be found in the Java Lab documentation.

Powered by Zendesk