Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
An operator performs a function on one, two, or three operands. An operator that requires one operand is called a unary operator. For example,++
is a unary operator that increments the value of its operand by 1. An operator that requires two operands is a binary operator . For example,=
is a binary operator that assigns the value from its right-hand operand to its left-hand operand. And finally, a ternary operator is one that requires three operands. The Java programming language has one ternary operator,?:
, which is a short-handif
-else
statement.The unary operators support either prefix or postfix notation. Prefix notation means that the operator appears before its operand:
Postfix notation means that the operator appears after its operand:operator op //prefix notationAll of the binary operators use infix notation, which means that the operator appears between its operands:op operator //postfix notationThe ternary operator is also infix; each component of the operator appears between operands:op1 operator op2 //infix notationIn addition to performing the operation, an operator returns a value. The return value and its type depend on the operator and the type of its operands. For example, the arithmetic operators, which perform basic arithmetic operations such as addition and subtraction, return numbers-the result of the arithmetic operation. The data type returned by an arithmetic operator depends on the type of its operands: If you add two integers, you get an integer back. An operation is said to evaluate to its result.op1 ? op2 : op3 //infix notationWe divide the operators into these categories:
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2004 Sun Microsystems, Inc. All rights reserved.