Why FRC Teams Use Java
WPILib officially supports three text languages — Java, C++, and Python — and its own docs encourage new and inexperienced users to start with Java. The practical reasons:
- Forgiving. Java manages memory for you and checks types before the program runs, catching mistakes that would crash a C++ robot mid-match.
- Already taught. Java is the language of the AP Computer Science A exam and most high-school CS classes, so students often arrive knowing it.
- Matches the examples. WPILib keeps Java and C++ nearly identical in class and method names, so tutorials translate cleanly.
- Most help available. The bulk of FRC sample code, ChiefDelphi posts, and public team repos are in Java.
Java is a little slower and uses more memory than C++, but on the roboRIO that gap won't matter to a beginner.
What WPILib Gives You
WPILib is the library your code uses to talk to the robot — motors, sensors, the controller, the Driver Station. Instead of writing low-level electronics code, you call clean methods like motor.set(0.5). Everything from the earlier lessons pays off here: WPILib is a big set of classes you build with new, call with the dot operator, and extend with inheritance.
Reading a Minimal Robot File
This is the shape of a basic WPILib robot. You already know every piece:
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.motorcontrol.PWMSparkMax;
import edu.wpi.first.wpilibj.XboxController;
public class Robot extends TimedRobot {
private final PWMSparkMax motor = new PWMSparkMax(0); // PWM port 0
private final XboxController driver = new XboxController(0);
@Override
public void teleopPeriodic() {
double speed = driver.getLeftY(); // -1.0 to 1.0
motor.set(speed);
}
}
Line by line:
importpulls in WPILib classes so you can use them by name.extends TimedRobot— inheritance gives you the 50 Hz loop and match-mode handling for free.private final ... = new ...— you create objects (a motor controller, a controller) as fields.finalmeans "don't reassign this box," and the0is a constructor argument: the hardware port.@Override public void teleopPeriodic()— the method WPILib calls every ~20 ms during driver control.- Inside: a variable, a method call returning a
double, another method call — the building blocks from Lessons 1 and 2.
How to Read Unfamiliar WPILib Code
- Find the
extends/implementsto see what the class already is. - Spot the
newcalls to see what hardware or helpers it builds. - Trace the
@Overridemethods — those run automatically; everything else is called from inside them. - Look the method up in the WPILib Java API docs (Javadocs) to confirm its inputs and return value. Reading docs is a core skill, not cheating.
Variables and types, control flow and methods, classes and inheritance — that's enough to read and start modifying real FRC code in Java. The department's main lessons build straight from here.
Key takeaways
- WPILib officially supports Java, C++, and Python, and recommends Java for newcomers for its balance of safety and convenience.
- Java is forgiving (garbage collection, compile-time type checks), widely taught, and has the largest FRC code community.
- WPILib is a library of classes you use with `new`, the dot operator, and inheritance — the OOP basics in action.
- A basic robot file `extends TimedRobot`, creates hardware objects as fields, and overrides `teleopPeriodic()`.
- Read unfamiliar library code by finding `extends`, `new`, and `@Override`, then checking the official WPILib API docs.
Go deeper
Lesson quiz
RequiredAnswer all 3 questions correctly to complete this lesson.
01.Which programming languages does WPILib officially support for FRC?
02.In `new PWMSparkMax(0)`, what does the 0 most likely represent?
03.Why does WPILib recommend Java for new FRC programmers?
Answer every question to submit.
All 51 lessons in Programming, Controls & Sensors
- Not started:Mini-Project: A Closed-Loop Elevator with Motion Magic
- Not started:Mini-Project: A Velocity-Controlled Shooter on REVLib
- Not started:Mini-Project: A Teleop Swerve Drive Subsystem
- Not started:Mini-Project: An Autonomous Routine with PathPlanner
- Not started:Mini-Project: Vision-Aligned Scoring with Limelight
- Not started:State-Space Control and Kalman Filtering
- Not started:Log Replay Architecture with AdvantageKit
- Not started:Advanced Pose Estimation: Multi-Tag Fusion and Standard Deviations
- Not started:Robot Coordination, Alerts, and Operator Feedback
- Not started:Case Study: Hardening Software Before an Event