Packages & Imports
Packages Are Folders for Classes
A package groups related classes together — like a folder. edu.wpi.first.wpilibj2.command is a real WPILib package holding all the command-based framework's classes.
Importing a Class
To use a class from another package, import it at the top of your file:
package frc.robot.subsystems;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import com.revrobotics.CANSparkMax;
public class Drivetrain extends SubsystemBase { ... }
The package line at the top says where this file lives; each import brings in one class from somewhere else so you can use it by its short name (SubsystemBase) instead of its full path.
One Package Needs No Import
java.lang is special — its classes (String, System, and a handful of others) are always available, in every Java file, with no import needed. That's why you've been able to use System.out.println and String this whole time without importing anything.
Common Pitfalls
- Forgetting an import. If a class isn't in
java.langand isn't in your own package, using it without importing it is a compile error. - Importing something you don't use. Not a functional bug, but most IDEs will flag it — it's just clutter.
Key Takeaways
- A package groups related classes together, the way a folder groups related files.
importbrings a class from another package into your file so you can use its short name.java.lang(which includesStringandSystem) never needs an import — it's always available.
Derived from csawesome-2026: unit-1-using-objects-and-methods/1.07-apis-and-libraries.md (CSA 1.7 §1.7.2)