Java Operator Precedence Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What’s of the top (15th) precedence?

A

() - Parentheses
[] - Array subscript
· - Member selection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s of the last (1st) precedence?

A
=       -Assignment
\+=     -Addition Assignment
-=      -Subtraction Assignment
*=      -Multiplication Assignment 
/=      -Division Assignment
%=    -Modulus Assignment
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does Precedence even mean?

A

it’s the condition of being more important that something; priority

in this case, the higher the #, the higher it is in priority

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

14th precedence?

A

? : -conditional (ternary)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

13th precedence?

A
\++       -unary Pre-Increment
--         -unary Pre-Decrement
\+         -unary Plus
-          -unary Minus
!          -unary Logical Negation
~         -unary Bitwise Complement
(type)  -unary Type Cast
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

12th precedence?

A
  • -Multiplication
    / -Division
    % -Modulus
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

11th precedence?

A

+ -Addition

- -Subtraction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

10th precedence?

A

&laquo_space; -bitwise Left Shift
» -bitwise Right Shift w/Sign Extension
»> -bitwise Right Shift w/Zero Extension

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

9th precedence?

A
<       -relational Less than 
<=     -relational Less than or Equal 
>       -relational Greater than
>=     -relational Greater than or Equal
instanceof      -Type comparison (objects only)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

8th precedence?

A
==     -relational Is Equal to 
!=      -relational Is Not Equal to
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

7th precedence?

A

& -bitwise AND

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

6th precedence?

A

^ -bitwise exclusive OR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

5th precedence?

A

-bitwise inclusive OR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

4th precedence?

A

&& -logical AND

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

3rd precedence?

A

|| -logical OR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What’s the order for Bitwise operators?

A

(10th precedence)
&laquo_space; -bitwise Left Shift
» -bitwise Right Shift w/Sign Extension
»> -bitwise Right Shift w/Zero Extension

(7th precedence)
& -bitwise AND

(6th precedence)
^ -bitwise exclusive OR

(5th precedence)
| -bitwise inclusive OR

17
Q

What’s the order for Relational operators?

A
(9th precedence)
<       -relational Less than 
<=     -relational Less than or Equal 
>       -relational Greater than
>=     -relational Greater than or Equal
instanceof      -Type comparison (objects only)

(8th precedence)
== -relational Is Equal to
!= -relational Is Not Equal to

18
Q

What’s the order for Unary operators?

A

(14th precedence)
++ -unary Post-Increment
– -unary Post-Decrement

(13th precedence)
\++        -unary Pre-Increment
--          -unary Pre-Decrement
\+          -unary Plus
-           -unary Minus
!           -unary Logical Negation
~          -unary Bitwise Complement
(type)   -unary Type Cast
19
Q

What’s the order for Math operators?

A

(15th precedence)
() - Parentheses
[] - Array subscript
· - Member selection

(12th precedence)
* -Multiplication
/ -Division
% -Modulus

(11th precedence)
+ -Addition
- -Subtraction

20
Q

(Check for understanding Math) Which one comes first?

  • Multiplication
  • Division
  • Modulus
A

None of them

It depends on the order from left to right

-b/c they are all within the same precedence, just as + and - have the same precedence as well.

21
Q

What’s the order for Boolean operators?

A

(13th precedence)
! -unary Logical Negation

(7th precedence)
& -bitwise AND

(6th precedence)
^ -bitwise exclusive OR

(4th precedence)
&& -logical AND

(3rd precedence)
|| -logical OR

22
Q

What makes the 14th, 13th, 2nd, and 1st precedence different from the rest?

A

Within Java, they operate going from Right to Left instead of Left to Right

This is what we call “Associativity”, whenever we have more than one expression with the same precedence, the order can change.

Ex) “3 + 3 + 3” is Left to Right (13th precedence)
“3 = 3 = 3” is Right to Left (2nd precedence)

23
Q

What is a Bitwise operator used for?

A

They’re used to manipulate r compare individual bits of a number

(works with char, short, int, etc.)

In use, it works like Booleans, except every 1 = true and 0 = false

24
Q

What is a Unary operator used for?

A

“Unary” means to have one operands

These operands can be increment (++), decrement (–), negation(!)

Increment and Decrement can be used in a Pre- or a Post- state

25
Q

What is a Ternary Conditional used for?

A

Ternary meaning three operands

The Ternary Condition acts as a simplified if-then-else statement and requires at least three operands(operations) to work

ex) 
variable = Expression1 ? Expression2: 
// which is the same thing as-
if(Expression1)
    variable = Expression2;
else
    variable = Expression3;
26
Q

What does Associativity mean again?

A

In this context, it’s the association/order that expressions within the same precedence are executed