chapter 3 Flashcards
What is an operator?
A special symbol that can be applied to a set of variables, values, or literals, and that returns a result.
What is an operand?
The value of variable the operator is being applied to.
In general, what are the three types of operators available in Java?
unary, binary, and ternary.
What is the order of operator precedence?
post-unary operators: foo++, foo--; pre-unary operators: ++foo, --foo; unary operators: -,!,~+,(type) mult/div/mod: *,/,% add/sub: +,- shift operators: <>,>>> relational operators: ,<=,>=,instanceof equal/not equal: ==, != logical operators: &,^,| short-circuit logical ops: &&, || ternary operators: boolean exp? exp1: exp2 assignment ops: =, +=,-=,*=,/=,%=,&=,^=,|=,<<=,>>=,>>>=
What is a unary operator?
An operator that requires exactly one operand to function.
List the unary operators in Java.
! -> Inverts a boolean logical value \+ -> Indicates a number is positive - -> Indicates a literal number is negative, or negates an expression \++ -> increments a value by 1 -- -> decrements a value by 1 (type) casts a value to a specific type
What is a binary operator?
An operator that takes two arguments.
List the binary operators.
+ -> Adds two numeric values.
- -> Subtracts two numeric values.
* -> Multiplies two numeric values.
/ -> Divides one numeric value by another.
% -> Returns the remainder after division of one numeric value by another.
What is the only primitive type arithmetic operators cannot be applied to?
boolean.
What are the only arithmetic operators that can be applied to String types?
+, +=
When parentheses are used in the exam, what are two things to pay attention to?
Are parentheses balanced?
How do the parentheses affect order of operations?
What are the 4 numeric promotion rules for primitives used during arithmetic operations?
- If two values differ in type, the value with the smaller type will be promoted to the larger.
- If one value is integral and the other floating-point, the integral will be promoted to the floating-point value’s data type.
- Any type smaller than an int will first be promoted to int when used with a Java binary arithmetic operator.
- The resulting value of some operation will have the same data type as its promoted operands.
What is an assignment operator?
A binary operator that modifies the variable on the left side of the operator with the result of the value on the right side of the equation.
What is casting?
A unary operation where one data type is explicitly interpreted as another data type.
When casting is present on the OCM exam, what are some things one pay attention to?
parentheses and return types.