Home | » | Java | » | Java Operators |
---|
Java provides a rich operator environment. Most of its operators can be divided into the following four groups: arithmetic, bit wise, relational and logical. Java also defines some additional operators that handle certain special situations. Each operator performs a specific task it is designed for.
Operators
Operators are the Special Symbols those have specific functions associated with them for Performing the operations it needs some Operands.
Operands are those on which operations are performed by the Operators
Like 2 +3
In this + is the Operator and 2 and 3 Operands.
The types of Operators those are supported by Java Language.
- Assignment Operator
- Arithmetic Operator
- Relational or Conditional Operators
- Logical Operators
- Increment & Decrement Operators
- Conditional or Ternary Operator
- Special Operator
Assignment Operator
Assignment Operator (=) is used for Initializing a value to variable or we can say that an assignment operator is used for Assigning a value to the variable.
for Ex:
a=10
in this a is name of the Variable and 10 is the value that is Given with the help of the assignment Operator. In This Left side variable contains the Value at Right Side But It Does n t Matter what a variable Contains before Assigning if a Variable Contains a value then it Overrides the Previous Value and it contains a new value that is Specified.
Arithmetic Operators
The Arithmetic Operators are used for Performing the Mathematical Operations on operands Like + , - , / , * , %
Operator | Result |
---|---|
% | is Called as Modulus or Remainder operator Which gives us the Remainder after division. |
+ | For Addition |
- | for Subtraction |
* | For Multiplication |
/ | For Division |
% | For Modulus |
Relational or Conditional Operators
The Relational Operators are used for Checking the Conditions or These operators are used for Controlling the Flow of the Execution to First Check the Condition it Contains
Operator | Result |
---|---|
< | Less Than |
> | Greater Then |
>= | Greater then Equals to |
<= | Less Than Equals To |
! | boolean not |
!= | not equal to |
Logical Operators
The boolean logical operators shown here operate only on boolean operands. All of the binary logical operators combine two boolean values to form a resultant boolean value.
Operator | Result |
---|---|
& | Logical AND |
| | Logical OR |
^ | Logical XOR (exclusive OR) |
|| | short Circuit OR |
&& | Short Circuit AND |
! | Logical Unary Not |
&= | AND ASSIGNMENT |
|= | OR ASSIGNMENT |
^= | XOR ASSIGNMENT |
== | Equal To |
!= | Not Equal To |
?: | Termary if then else |
Increment Decrement Operators
Increment/Decrement Operators is Counter Operator. These are two as: ++ (increment operator) and -- (decrement operator). Increment operator are used for incrementing the value one by one. Similarly decrement operator are used for decrementing the value one by one. These are further sub-divided into two categories:
a) Prefix Increment / Decrement Operator
b) Postfix Increment / Decrement Operator
a) Prefix Operator:
In the Prefix increment operator, first of all value will be increment and the incremented value will be assigned to a variable. Similarly in the prefix decrement operator first of all value will be decrement and then decremented value be assigned to the variabl. The general way is represendted as:
++v;
--v;
b) Postfix Operator:
In the postfix increment operator, first of all value will be assigned to a variable and then it will be incremented. Similarly in the postfix decrement operator first of all value will be assigned and then it will be decremented. The general way is represendted as:
v++;
v--;
Conditional Operator
This operator is used When we wants to specify the value of Variable by first checking a condition This Operator Works Similar to if else :- In this First it checks the condition if it is true then it will gives the result and if a condition will false then it also Gives Some Values to the Variables
This Operator Contains ? :
For Ex:
Int A,B
A=10
B=20
C=(A>B) ? 13 : 20
In this First ? Will Check Whether a Condition is true or not if it is true then it will gives the value 13 to C or if Condition is False Then it will gives 20 the C Variable
Special Operators
Java Also Provides Some Special Operators Like Instance of For checking Whether an Object is Instance of a Class or Whether an object is related to Class this will gives result true or either False
Dot Operator
Dot Operator is used for Accessing the data and Member Function of class and This is used by Object of Class An Object Communicates With the Member Functions of Class With the Help of Dot Operator.
Thanks for sharing valuable information.
ReplyDeleteJava Training in Chennai
Nice article. Keep Up with good work.
ReplyDeleteJava training in Pune