the video version
The same lesson as a narrated video. Watch it on YouTube
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.
the part worth keeping
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.
Programming, Controls & SensorsProgramming Foundations: A Java Primerlesson 4 of 4
Keep going
Take the quiz+10 XP with an accountMore in Programming Foundations: A Java Primer
where this came from
Sources and corrections
This lesson is AI-assisted: drafted from primary sources, then reviewed and edited by hand. Errors still get through. When one is reported we fix it and write down what changed, in public, in the corrections log.
sources and further reading
- docs.wpilib.orgWPILib Docs: What is WPILib?
- docs.wpilib.orgWPILib Docs: Zero to Robot Introduction
- docs.wpilib.orgWPILib Docs: Creating a Robot Program
- dev.javadev.java: Getting Started with Java
clipped to this lesson
Articles that go further on this
The lesson gets you through the topic. These go wider on it, and they read in one sitting.
- 7 min readFRC Programming Languages: Java vs C++ vs PythonAn honest, beginner-friendly comparison of the three WPILib-supported FRC languages — Java, C++, and Python (RobotPy) — with vendor support and how to choose./blogread it
- 7 min readFRC "No Robot Code" & Driver Station Won't Connect: Full Fix ChecklistA verified, step-by-step FRC troubleshooting decision tree for "No Robot Code" and a Driver Station that won't connect to the roboRIO — most common causes first./blogread it
- 13 min readWPILib Won't Deploy: Every Cause and How to Fix ItYour WPILib deploy is failing? Work the decision tree: wrong folder in VS Code, team number, roboRIO image, JDK version, macOS network privacy. Fixes for each./blogread it
answer sheet
Lesson quiz
All 3 right completes the lesson. Miss one and only that question comes back, anything you already answered correctly stays banked.
0 of 3 answered
01Which programming languages does WPILib officially support for FRC?
02In `new PWMSparkMax(0)`, what does the 0 most likely represent?
03Why does WPILib recommend Java for new FRC programmers?
Answer every question to submit.
All 51 lessons in Programming, Controls & Sensorsopenclose
01 / prerequisites
02 / foundations-tools-and-first-program
03 / robot-program-and-command-based
04 / motors-and-control
05 / autonomous-trajectories-simulation
06 / sensing-fundamentals
07 / encoders
08 / gyros-imus-orientation
09 / closed-loop-control
10 / vision-pose-estimation
11 / worked-examples-mini-projects
- Not read yet:Mini-Project: A Closed-Loop Elevator with Motion Magic
- Not read yet:Mini-Project: A Velocity-Controlled Shooter on REVLib
- Not read yet:Mini-Project: A Teleop Swerve Drive Subsystem
- Not read yet:Mini-Project: An Autonomous Routine with PathPlanner
- Not read yet:Mini-Project: Vision-Aligned Scoring with Limelight
12 / common-mistakes-troubleshooting
13 / advanced-techniques-case-studies
- Not read yet:State-Space Control and Kalman Filtering
- Not read yet:Log Replay Architecture with AdvantageKit
- Not read yet:Advanced Pose Estimation: Multi-Tag Fusion and Standard Deviations
- Not read yet:Robot Coordination, Alerts, and Operator Feedback
- Not read yet:Case Study: Hardening Software Before an Event