---
spec: JLS
title: "The Java Language Specification"
edition: "Java SE 26 Edition"
java_version: 26
chapter: "Chapter 14. Blocks, Statements, and Patterns"
section: "14.8"
heading: "14.8. Expression Statements"
parent: "Chapter 14. Blocks, Statements, and Patterns"
source: https://docs.oracle.com/javase/specs/jls/se26/html/jls-14.html#jls-14.8
id: "14.8"
url: https://jvm.obfuscated.software/jls/se26/14.8.html
raw: https://jvm.obfuscated.software/jls/se26/14.8.md
---

# 14.8. Expression Statements

Certain kinds of expressions may be used as statements by following them with semicolons.

```
ExpressionStatement:
  StatementExpression ;

StatementExpression:
  Assignment
  PreIncrementExpression
  PreDecrementExpression
  PostIncrementExpression
  PostDecrementExpression
  MethodInvocation
  ClassInstanceCreationExpression
```

An *expression statement* is executed by evaluating the expression; if the expression has a value, the value is discarded.

Execution of the expression statement completes normally if and only if evaluation of the expression completes normally.

Unlike C and C++, the Java programming language allows only certain forms of expressions to be used as expression statements. For example, it is legal to use a method invocation expression ([§15.12](15.12.md)):

```
System.out.println("Hello world");  // OK
```

but it is not legal to use a parenthesized expression ([§15.8.5](15.8.5.md)):

```
(System.out.println("Hello world"));  // illegal
```

Note that the Java programming language does not allow a "cast to `void`" - `void` is not a type - so the traditional C trick of writing an expression statement such as:

```
(void)... ;  // incorrect!
```

does not work. On the other hand, the Java programming language allows all the most useful kinds of expressions in expression statements, and it does not require a method invocation used as an expression statement to invoke a `void` method, so such a trick is almost never needed. If a trick is needed, either an assignment statement ([§15.26](15.26.md)) or a local variable declaration statement ([§14.4](14.4.md)) can be used instead.
