Space Academy 3.0 is open — want to become a project contributor?Join in

Programming

Java Fundamentals

The subset of Java that actually matters for writing robot code.

1 min readUpdated Jul 26, 2026

You do not need all of Java to write great robot code. You need classes, fields, methods, control flow, and a working mental model of references.

Classes and objectsLink to this section

A subsystem is a class. Its fields hold hardware references and state; its methods expose intent to the rest of the robot.

java
public class Intake {
    private final DcMotor motor;
    private static final double COLLECT_POWER = 0.85;

    public Intake(HardwareMap hardwareMap) {
        motor = hardwareMap.get(DcMotor.class, "intake");
        motor.setZeroPowerBehavior(DcMotor.ZeroPowerBehavior.BRAKE);
    }

    public void collect() { motor.setPower(COLLECT_POWER); }
    public void eject()   { motor.setPower(-COLLECT_POWER); }
    public void stop()    { motor.setPower(0); }
}

Types you will use constantlyLink to this section

TypeUseNote
doubleMotor power, angles, distancesDefault for all math
intEncoder ticks, countersTicks are integers, never floats
booleanSensor states, togglesDebounce gamepad reads
enumRobot statesFar safer than magic ints

Enums for state machinesLink to this section

java
private enum LiftState { IDLE, RAISING, HOLDING, LOWERING }
private LiftState state = LiftState.IDLE;