Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

Multiplication operator (*)

The * operator computes the product of two numeric values. Operand types determine the result type; integer overflow does not throw an exception.

Version: Java SE 21; repository runtime, production runtime not attested

Syntax

leftOperand * rightOperand

The binary * operator multiplies numbers. It has higher precedence than binary + (addition) and - (subtraction), but lower precedence than unary + and -. The *, /, and % operators group left to right. Parentheses change grouping.

Numeric promotion selects a common operand and result type: double, then float, then long, otherwise int. Thus byte, short, and char participate as int unless the other operand requires a wider type. Numeric wrapper objects are unboxed; unboxing null throws NullPointerException.

Overflow of int or long retains the product’s low-order bits without an exception. Assignment to long cannot repair prior overflow: widen an operand before multiplication, as in the example.

Multiplication of float and double can round, overflow to infinity, or underflow. NaN propagates, and zero multiplied by infinity produces NaN.

Examples

public class Main {
    public static void main(String[] args) {
        int side = 50_000;
        System.out.println(6 * 7);
        System.out.println(side * side);
        System.out.println((long) side * side);
    }
}

Result

42
-1794967296
2500000000

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources