Operator
연산자
- 연산자는 하나 이상의 Operand(피연산자) 에 대한 특정 연산을 수행하고 그 결과를 반환하게 하는 특별한 Symbol 이다.
- 우선순위가 높은 연산자는 상대적으로 낮은 연산자보다 먼저 Evaluation(평가, 처리) 되고,
동일한 우선순위를 가진 연산자들이 하나의 Expression 에 위치할 경우,
Assignment Operator(할당 연산자) 이외의 모든 Binary Operator(이진 연산자) 는 왼쪽에서 오른쪽으로 평가되고,
할당 연산자는 오른쪽에서 왼쪽으로 평가된다.
Category (카테고리) |
Operator (연산자) |
Description (설명) |
Arithmetic Operator (산술 연산자) |
+ | - Additive Operator - String concatenation Operator ; indicates positive value (numbers are positive without this, however) |
- | - Subtraction Operator |
|
* | - Multiplication Operator |
|
/ | - Division Operator |
|
% | - Remainder Operator |
|
Assignment Operator (대입 연산자) |
= | - Simple Assignment Operator |
Unary Operator (단항 연산자) |
+ | - Unary Plus Operator |
- | - Unary Minus Operator |
|
++ | - Increment Operator |
|
-- | - Decrement Operator |
|
! | - Logical Complement Operator |
|
Equality Operator |
== | - Equal to Operator |
!= | - Not Equal to Operator |
|
> | - Greater than Operator |
|
>= | - Greater than or Equal to Operator |
|
< | - Less than Operator |
|
<= | - Less than or Equal to Operator |
|
Conditional Operator |
&& | - Conditional AND Operator |
|| | - Conditional OR Operator |
|
Type Comparison Operator | instanceof | - Type Comparison Operator |
Bitwise Operator |
& | - Bitwise AND Operator |
^ | - Bitwise Exclusive OR Operator |
|
| | - Bitwise Inclusive OR Operator |
|
Bit Shift Operator |
<< | - Signed Left Shift Operator |
>> | - Signed Right Shift Operator |
|
>>> | - Unsigned Right Shift Operator |
Operator Precedence (연산자 우선순위)
- 아래 연산자 우선순위 표에서 맨 위에 가까울수록 우선순위가 높은 연산자임을 의미하고,
동일한 선에 위치한 연산자들끼리는 같은 우선순위를 가진다.
Operator (연산자) |
Precedence (우선순위) |
Postfix | expr++ expr-- |
Unary | ++expr --expr +expr -expr ~ ! |
Multiplicative | * / % |
Additive | + - |
Shift | << >> >>> |
Relational | < > <= >= instanceof |
Equality | == != |
Bitwise AND | & |
Bitwise Exclusive OR | ^ |
Bitwise Inclusive OR | | |
Logical AND | && |
Logical OR | || |
Ternary | ? : |
Assignment | = += -= *= /= %= &= ^= |= <<= >>= >>>= |
Reference: Oracle, The Java™ Tutorials: Operators, URL, 2023년 2월 19일 검색
Reference: 신용권, 임경균; 이것이 자바다(개정판); 한빛미디어; 2022