> For the complete documentation index, see [llms.txt](https://docs.cb21829.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cb21829.org/ftc-java-beginner-guide/java-principles-you-actually-need-for-ftc-oop.md).

# Java principles you actually need for FTC (OOP)

You do not need all of Java. You need the OOP pieces the FTC SDK uses.

### Variables and types

```java
int ticks = 1120;
double power = 0.75;
boolean isPressed = true;
String motorName = "frontLeft";
```

Use `double` for motor powers and most robot math. Use `int` for encoder counts.

### Classes and objects

A **class** is a blueprint. An **object** is an instance of that blueprint.

```java
DcMotor frontLeft;
```

`DcMotor` is a class from the SDK. `frontLeft` is a variable that will point to a real motor object.

Your OpMode is also a class:

```java
public class MyFirstTeleOp extends LinearOpMode {
    // your code
}
```

### Inheritance with `extends`

`extends LinearOpMode` means your class inherits SDK behavior. That gives you `hardwareMap`, `telemetry`, `gamepad1`, `waitForStart()`, and `opModeIsActive()`.

### Methods

A **method** is a named block of code.

```java
public double average(double a, double b) {
    return (a + b) / 2.0;
}
```

Common SDK methods:

* `motor.setPower(0.5)`
* `motor.getCurrentPosition()`
* `imu.resetYaw()`

### Fields

Fields are variables declared at the class level.

```java
public class MyFirstTeleOp extends LinearOpMode {
    private DcMotor frontLeft;
    private DcMotor frontRight;

    @Override
    public void runOpMode() {
        frontLeft = hardwareMap.get(DcMotor.class, "frontLeft");
    }
}
```

Use fields for hardware objects you need across the class.

### Access modifiers

* `public` — accessible from anywhere.
* `private` — accessible only inside the class.

Default fields to `private` unless you need something else.

### Annotations

Annotations start with `@`.

```java
@TeleOp(name = "My First TeleOp", group = "Practice")
public class MyFirstTeleOp extends LinearOpMode { ... }
```

`@TeleOp` and `@Autonomous` make the OpMode appear on the Driver Station. `@Override` marks a method you are replacing from a parent class.

### Control flow

```java
if (gamepad1.a) {
    intake.setPower(1.0);
} else {
    intake.setPower(0.0);
}

while (opModeIsActive()) {
    // repeats until the OpMode stops
}
```

That is enough OOP to write solid FTC code.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.cb21829.org/ftc-java-beginner-guide/java-principles-you-actually-need-for-ftc-oop.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
