### Type of Operators

Java provides various types of operators(very much similar to C programming) that can be used to perform different operations on variables and values. These are:-

##### Arithmetic Operators
• They are divided into two categories – Binary Arithmetic Operators and Unary Arithmetic Operators.
• Binary Arithmetic Operators –
• Binary operators are applied only on two operands.
• Binary operators are – +, -, *, /, %
• Unary Arithmetic Operators –
• Unary operators are applied only to one operand.
• Unary operators are – ++, – –
• They are of two types – Increment unary operator and Decrement unary operator.
• Increment Unary Operator is further divided into two parts – Pre Increment Unary Operator(++i) and Post Increment Unary Operator(i++).
• The Decrement Unary operator is further divided into two parts – Pre decrement Unary Operator(–i) and Post Increment Unary Operator(i–).
##### Assignment Operators
• Denoted by = symbol.
• It is used to assign value to the variables. For example  int A = 12; int A = B; int C= A+B; char ch=’m’;
• Assignment operators can also be represented in the form of shorthand form/Compound assignment operators, therefore, they are represented as –
##### Relational/Comparision Operators
• Equal to (==): Checks if two operands are equal.
• Not equal to (!=): Checks if two operands are not equal.
• Greater than (>): Checks if the left operand is greater than the right.
• Less than (<): Checks if the left operand is less than the right.
• Greater than or equal to (>=): Checks if the left operand is greater than or equal to the right.
• Less than or equal to (<=): Checks if the left operand is less than or equal to the right.
##### Conditional/Ternary Operators
• Ternary operator (condition ? expression1: expression2): Evaluates a condition and returns one of two expressions based on the result of the condition.
##### Logical/Boolean Operators
• Logical AND (&&): Returns true if both operands are true.
• Logical OR (||): Returns true if either operand is true.
• Logical NOT (!): Inverts the logical state of an operand.
##### Bitwise Operators
• Bitwise AND (&): Performs a bitwise AND operation.
• Bitwise OR (|): Performs a bitwise OR operation.
• Bitwise XOR (^): Performs a bitwise XOR (exclusive OR) operation.
• Bitwise NOT (~): Inverts the bits of an operand.
• Left shift (<<): Shifts the bits of the left operand to the left.
• Right shift (>>): Shifts the bits of the left operand to the right.
• Unsigned right shift (>>>): Shifts the bits of the left operand to the right, filling the leftmost bits with zeros.
##### Class & Object Operators
 Symbol Name Description instance of Class Test Operator Checks if an object is an instance of a specific class or a subclass. The first operand must be an object reference. For example ‘A instance of B’, Returns true if A is an instance of B. Otherwise, it returns false. new Class Instantiation Creates a new object. For example: new A, in this A is either a call to a constructor or an array specification. “.” Class Member Access It accesses a method or field of a class or object. For example, A.B is used for ‘field access for object A’, and A.B() is used for ‘method access for object A’ () Method Invocation For example, A(parameters), Declares or calls the method named A with the specified parameters. (type) Object Cast (type) A, in this example () operator Cost (convert) A to a specific type. An exception will be thrown if the type of A is incompatible with the specified type. This type can be an object or any primitive data type.
##### Others Operators
 [ ] type [ ] Declares an array of unknown length, which contains type elements. type[ A ] Creates an array with A elements. Must be used with the new operator. A[ B ] Accesses the element at index B within array A. Indices begin at 0 and extend through the length of the array minus one. + A+B This binary operator concatenates one string to another. For example: –String str1 = “Welcome”; String str2 = “Codershelpline”; String str3 = str1 + str2Output str3 = Welcome Codershelpline.

For more Details Click This Link

Categories: Java