Home     Blog

Java Operators

java operators 150x150 Java Operators

Java Operator Operator Description
[ ] Array index
() Method call
. Member access
++ Prefix or postfix increment
-- Prefix or postfix decrement
+ - Unary plus, minus
~ Bitwise NOT
! Boolean (logical) NOT
(type) Type cast
new Object creation
* / % Multiplication, division, remainder
+ - Addition, subtraction
+ String concatenation
<< Signed bit shift left to right
>> Signed bit shift right to left
>>> Unsigned bit shift right to left
< <= Less than, less than or equal to
> >= Greater than, greater than or equal to
instanceof Reference test
== Equal to
!= Not equal to
& Bitwise AND
& Boolean (logical) AND
^ Bitwise XOR
^ Boolean (logical) XOR
| Bitwise OR
| Boolean (logical) OR
&& Boolean (logical) AND
|| Boolean (logical) OR
? : Conditional
= Assignment
*= /= += -= %= <<= >>= >>>= &= ^= |= Combinated assignment (operation and assignment)

Java Operator Precedence

Java operator precedence is how Java determines which operator to evaluate first.

In this chart, operator precedence is displayed from highest precedence to lowest precedence.

Priority Operator Operation Order of Evaluation
1 [ ] Array index Left to Right
() Method call
. Member access
2 ++ Prefix or postfix increment Right to Left
-- Prefix or postfix decrement
+ - Unary plus, minus
~ Bitwise NOT
! Boolean (logical) NOT
(type) Type cast
new Object creation
3 * / % Multiplication, division, remainder Left to Right
4 + - Addition, subtraction Left to Right
+ String concatenation
5 << Signed bit shift left to right Left to Right
>> Signed bit shift right to left
>>> Unsigned bit shift right to left
6 < <= Less than, less than or equal to Left to Right
> >= Greater than, greater than or equal to
instanceof Reference test
7 == Equal to Left to Right
!= Not equal to
8 & Bitwise AND Left to Right
& Boolean (logical) AND
9 ^ Bitwise XOR Left to Right
^ Boolean (logical) XOR
10 | Bitwise OR Left to Right
| Boolean (logical) OR
11 && Boolean (logical) AND Left to Right
12 || Boolean (logical) OR Left to Right
13 ? : Conditional Right to Left
14 = Assignment Right to Left
*= /= += -= %= <<= >>= >>>= &= ^= |= Combinated assignment (operation and assignment)

Notes

  • Expressions inside parentheses are evaluated first
  • Nested parentheses are evaluated from the innermost parentheses to the outermost parenthesis.
  • Operators in the same row in the chart have equal precedence.
VN:F [1.9.17_1161]
Rating: 0.0/10 (0 votes cast)
Follow Will.Spencer on

Leave a Reply

Related Posts

  • Java vs. C++

    C++ supports pointers; Java does not (Java does have object references) C++ supports mutiple inheritance directly; Java supports multiple inheritance only through interfaces C++ supports operator overloading; Java does not C++ supports global variables; Java does not (sort of) C++ supports #define; Java does not C++ supports typedef; Java does not C++ supports enum; Java [...]...


  • Java Data Types

    Java has two groups of data types, primitive data types and object references. Java Primitive Data Types Data Type Purpose Contents Default Value* boolean Truth value true or false fales char Character Unicode characters u0000 byte Signed integer 8 bit two’s complement (byte) 0 short Signed integer 16 bit two’s complement (short) 0 int Signed [...]...


  • Java Source Code

    Java source code is code that you write in the Java programming language. Java source code is converted to Java bytecode by the Java compiler. Java source code files usually have the .java extension. Sun recommends that Java source code files be no longer than two thousand lines. Larger source code files should be split [...]...


  • Java Compiler

    A Java compiler is a program which converts Java source code into Java bytecode. A basic Java compiler is included as part of the JDK (Java Development Kit). This Java compiler is called “javac”.              ...


  • Java Class

    A Java class is a group of Java methods and variables. Each Java source code file can contain one public class. The name of this public class must match the name of the Java source code file. If the public class is called “ballistics,” then the filename would be “ballistics.java.” Example Java Class class Ammunition [...]...