---
title: "Expression — AP Computer Science A Definition & Examples"
description: "An expression combines values, variables, and operators to produce a single value in Java. Learn how AP CSA tests expressions through assignment, casting, and evaluation MCQs."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/expression"
type: "key-term"
subject: "AP Computer Science A"
unit: "Unit 1"
---

# Expression — AP Computer Science A Definition & Examples

## Definition

In AP Computer Science A, an expression is any combination of values, variables, operators, and method calls that Java evaluates to produce a single value of a specific type, like (double)a / b or temp + 0.5, which can then be stored in a variable with an assignment statement.

## What It Is

An expression is anything Java can evaluate down to one value. That includes a single [literal](/ap-comp-sci-a/unit-1/expressions-and-assignment-statements/study-guide/01dr6uUPDAn3SjtK2Psr "fv-autolink") like `5`, a variable like `temp`, or a longer combination like `(double)a / b + (int)(c * 2)`. No matter how complicated it looks, every expression boils down to exactly one value with exactly one type (an `int`, a `double`, a `boolean`, a `String`, and so on).

In [Topic 1.4](/ap-comp-sci-a/unit-1/14-assignment-statement-input/study-guide/compoundassignment "fv-autolink"), expressions show up on the right side of the assignment operator `=`. Java evaluates the expression on the right first, then stores the result in the variable on the left (EK 1.4.A.2). The type of that result has to be compatible with the variable's type (EK 1.4.A.1), which is exactly why [casting](/ap-comp-sci-a/unit-1/casting-and-ranges-of-variables/study-guide/kW3XXEIwJwVRXFx3ntdC "fv-autolink") and int-vs-double division matter so much. Think of an expression as a tiny machine. You feed it values and operators, it follows precedence rules, and it spits out one answer.

## Why It Matters

Expressions live in **[Unit 1](/ap-comp-sci-a/unit-1 "fv-autolink"): Using Objects and Methods**, specifically **Topic 1.4: Assignment Statements and Input**. Learning objective **[AP Comp Sci A](/ap-comp-sci-a "fv-autolink") 1.4.A** asks you to develop code for assignment statements with expressions and determine the value stored in the variable as a result. That second part is the big one. A huge slice of AP CSA multiple choice is literally just "what is the value of x after this code runs?" and answering it means evaluating expressions correctly, including integer division truncation, the modulus operator, and casts. Expressions are also the foundation for everything later. Boolean expressions drive conditionals and loops, and method calls inside expressions return values you use everywhere. If you can't evaluate an expression by hand, almost no other AP CSA skill works.

## Connections

### Assignment Statements (Unit 1)

Expressions and assignment statements are a [package](/ap-comp-sci-a/key-terms/package "fv-autolink") deal. The expression on the right of `=` gets evaluated first, and its single result gets stored in the variable on the left. An expression produces a value; an assignment statement is what you do with it.

### Casting and Integer Division (Unit 1)

The type of an expression's result depends on the types inside it. Two ints divided give a truncated int, but cast one to double and you get a decimal answer. Casts like `(double)a / b` and the rounding trick `(int)(temp + 0.5)` are the most-tested expression details in Unit 1.

### Boolean Expressions in Conditionals (Unit 2)

Once expressions can produce `boolean` values using comparison operators, they become the conditions inside if statements and loops. Same evaluation skill, new payoff. Every branch your program takes is decided by an expression evaluating to true or false.

### Method Calls That Return Values (Unit 1)

A [method call](/ap-comp-sci-a/key-terms/method-call "fv-autolink") like `scan.nextDouble()` or `Math.sqrt(x)` is itself an expression because it evaluates to a single value. That's why you can drop it straight into a bigger expression or onto the right side of an assignment.

## On the AP Exam

Expressions are tested constantly but almost never by name. The classic MCQ stem hands you a code segment and asks "what is the value of num after executing this code?" For example, given `double temp = 7.8;` and `int num = (int)(temp + 0.5);`, you have to evaluate the expression step by step (7.8 + 0.5 = 8.3, then the cast truncates to 8). Harder versions stack casting, integer division, and modulus into one expression, like `(double)a / b + (int)(c * 2) - (int)(a % b + 0.7)`, and the wrong answer choices are exactly what you get if you truncate at the wrong moment or forget operator precedence. On FRQs, you won't be asked to define an expression, but every line of code you write uses them. The 2019 FRQs on string processing and the LightBoard class both required writing expressions to compute indexes, counts, and boolean conditions. Practice evaluating expressions on paper, since you won't have a compiler to catch your mistakes.

## expression vs Statement

An expression evaluates to a value; a statement is a complete instruction that does something. `temp + 0.5` is an expression because it produces one value (8.3). `int num = (int)(temp + 0.5);` is a statement because it performs an action, storing a value in num. Easy check: expressions could appear on the right side of `=`, while statements end with a semicolon and stand alone.

## Key Takeaways

- An expression is any combination of values, variables, operators, and method calls that evaluates to exactly one value of one type.
- In an assignment statement, Java evaluates the expression on the right side of = first, then stores that result in the variable on the left (EK 1.4.A.2).
- Every variable must be assigned a compatible value before it can be used in an expression, and the first assignment is called initialization (EK 1.4.A.1).
- The types inside an expression control the result, so int / int truncates to an int while a cast like (double)a / b keeps the decimal.
- The pattern (int)(x + 0.5) rounds a positive double to the nearest int, and it shows up repeatedly in AP CSA multiple choice.
- When evaluating expressions on the exam, work inside-out and apply casts at the exact moment they appear, because most wrong answer choices come from truncating too early or too late.

## FAQs

### What is an expression in AP Computer Science A?

An expression is a combination of values, variables, operators, and [method](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz "fv-autolink") calls that Java evaluates to produce a single value of a specific type. Even something as simple as the literal 5 or the variable temp counts as an expression.

### What's the difference between an expression and a statement in Java?

An expression produces a value, like temp + 0.5, while a statement is a complete instruction that performs an action, like int num = (int)(temp + 0.5);. Assignment statements contain expressions on the right side of the = operator.

### Does an expression always have to be on the right side of an assignment?

No. Expressions also appear as arguments inside method calls, as conditions in if statements and loops, and inside return statements. Anywhere Java needs a value, an expression supplies it.

### Why does (int)(7.8 + 0.5) equal 8 and not 7?

Java evaluates the expression inside the parentheses first, so 7.8 + 0.5 gives 8.3, and then the (int) cast truncates the decimal to get 8. This rounding trick, (int)(x + 0.5), is a favorite on AP CSA multiple choice.

### Is a method call like scan.nextDouble() an expression?

Yes, if the method returns a value. A call like scan.nextDouble() evaluates to a single double, so you can assign it to a variable or use it inside a larger expression, exactly like any other expression.

## Related Study Guides

- [1.4 Assignment Statements and Input](/ap-comp-sci-a/unit-1/14-assignment-statement-input/study-guide/compoundassignment)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/expression#resource","name":"Expression — AP Computer Science A Definition & Examples","url":"https://fiveable.me/ap-comp-sci-a/key-terms/expression","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/expression#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T05:27:19.318Z","isPartOf":{"@type":"Collection","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/expression#term","name":"expression","description":"In AP Computer Science A, an expression is any combination of values, variables, operators, and method calls that Java evaluates to produce a single value of a specific type, like (double)a / b or temp + 0.5, which can then be stored in a variable with an assignment statement.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/expression","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is an expression in AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"An expression is a combination of values, variables, operators, and [method](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz \"fv-autolink\") calls that Java evaluates to produce a single value of a specific type. Even something as simple as the literal 5 or the variable temp counts as an expression."}},{"@type":"Question","name":"What's the difference between an expression and a statement in Java?","acceptedAnswer":{"@type":"Answer","text":"An expression produces a value, like temp + 0.5, while a statement is a complete instruction that performs an action, like int num = (int)(temp + 0.5);. Assignment statements contain expressions on the right side of the = operator."}},{"@type":"Question","name":"Does an expression always have to be on the right side of an assignment?","acceptedAnswer":{"@type":"Answer","text":"No. Expressions also appear as arguments inside method calls, as conditions in if statements and loops, and inside return statements. Anywhere Java needs a value, an expression supplies it."}},{"@type":"Question","name":"Why does (int)(7.8 + 0.5) equal 8 and not 7?","acceptedAnswer":{"@type":"Answer","text":"Java evaluates the expression inside the parentheses first, so 7.8 + 0.5 gives 8.3, and then the (int) cast truncates the decimal to get 8. This rounding trick, (int)(x + 0.5), is a favorite on AP CSA multiple choice."}},{"@type":"Question","name":"Is a method call like scan.nextDouble() an expression?","acceptedAnswer":{"@type":"Answer","text":"Yes, if the method returns a value. A call like scan.nextDouble() evaluates to a single double, so you can assign it to a variable or use it inside a larger expression, exactly like any other expression."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science A","item":"https://fiveable.me/ap-comp-sci-a"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-a/key-terms"},{"@type":"ListItem","position":3,"name":"Unit 1","item":"https://fiveable.me/ap-comp-sci-a/unit-1"},{"@type":"ListItem","position":4,"name":"expression"}]}]}
```
