Operators Flashcards
Operators
• Operators are tokens that carry out specific
operations on data.
• The data could be a variable or a constant or
a literal or an expression and it is known as
an Operand.
Classification of operators based on number of operands
- Unary - act on one operands
- Binary - act on two operands
- Ternary - act on three operands
Classification of operators based on operations
• Based on the type of operations they perform, they are classified as[CARLA]: - Conditional operators - Arithmetic operators - Relational operators - Logical operators - Assignment operators – Shift operators (not included in syllabus) – Bit-wise operators (not included in syllabus)
Precedence of operators
• This determines the order in which the
expressions are evaluated. Java uses BODMAS
and Associativity rules to evaluate an expression.
The order of evaluation is as follows:
1. Expression with Parenthesis
2. Prefix Operators (Increment ++, Decrement –)
3. Arithmetic operators
4. Relational operators
5. Logical Operators
6. Assignment Operators
Operator Associativity
• When more than one operation in an expression has the same precedence, then the associativity rules determine the order of the operations. Associativity rules determine the grouping of operands and operators in an expression.
Modulus operator
It is used for finding the remainder in a division operation
Plus operator
- Adding literals, variables, constants or expressions of numeric data types
- Concatenating strings
Unary minus
It negates an arithmetic operand’s value.
Division operator
- Returns the quotient created by the integer division of a whole number when it’s operands are of integral data types.
- Returns the quotient created by the division of its operands when one of its operands are of fractional data types.
Relational operators
Relational operators are used for comparing two different operands. The operands can be variables, literals or arithmetic expressions. If the comparison is true, it results into the boolean value true and if the comparison is false it results into the Boolean value false.
They do not work with Strings.
Logical operators
These operators are used for forming more complex
expressions. They are used for combining two relational
expressions.
Equals operator
• = is used for assigning a literal or a variable or the result of an expression to a variable on the left hand side.
Presedence of logical operators
! -> && -> ||