Java Basic Tutorial
Java Advance Tutorial
Operators in Java are special symbols or keywords used to perform operations on variables and values. Java supports a rich set of operators classified into different categories.
| Type | Description | 
|---|---|
| Arithmetic Operators | Perform basic arithmetic operations like addition, subtraction, etc. | 
| Relational Operators | Compare two values and return a boolean result. | 
| Logical Operators | Perform logical operations like AND, OR, etc., often used with boolean values. | 
| Assignment Operators | Assign values to variables. | 
| Ternary Operator | A shorthand for  | 
| Instanceof Operator | Test if an object is an instance of a specific class or subclass. | 
| Operator | Description | Example | Output | 
|---|---|---|---|
| + | Addition | 5 + 3 | 8 | 
| - | Subtraction | 5 - 3 | 2 | 
| * | Multiplication | 5 * 3 | 15 | 
| / | Division | 5 / 2 | 2(int) or 2.5(float) | 
| % | Modulus (remainder) | 5 % 2 | 1 | 
Try it yourself
| Operator | Description | Example | Output | 
|---|---|---|---|
| == | Equal to | 5 == 5 | true | 
| != | Not equal to | 5 != 3 | true | 
| > | Greater than | 5 > 3 | true | 
| < | Less than | 5 < 3 | false | 
| >= | Greater than or equal | 5 >= 5 | true | 
| <= | Less than or equal | 5 <= 3 | false | 
Try it yourself
| Operator | Description | Example | Output | 
|---|---|---|---|
| && | Logical AND | (5 > 3) && (3 > 1) | true | 
| || | Logical OR | (5 > 3) || (3 < 1) | true | 
| ! | Logical NOT | !(5 > 3) | false | 
Try it yourself
| Operator | Description | Example | Equivalent To | 
|---|---|---|---|
| = | Assign | a = 5 | ------ | 
| += | Add and assign | a += 5 | a = a + 5 | 
| -= | Subtract and assign | a -= 5 | a = a - 5 | 
| *= | Multiply and assign | a *= 5 | a = a * 5 | 
| /= | Divide and assign | a /= 5 | a = a / 5 | 
| %= | Modulus and assign | a %= 5 | a = a % 5 | 
Try it yourself
| Operator | Description | Syntax | Example | Output | 
|---|---|---|---|---|
| ? : | Shorthand for  | condition ? value1 : value2 | (5 > 3) ? 10 : 20 | 10 | 
Try it yourself
Try it yourself