Go to Top

Tuesday, 26 April 2011

Operators in Java

                                            The symbols used in a Java expression are known as Operators, whereas the values on which the operations are performed are known as Operands. There are three types of operators :

1. Unary Operator : These are the operators which require only one operand to perform the operation.
2. Binary Operator : These are the operators which require two operands to perform the operation.
3. Tertiary Operator : These are the operators which require three operands to perform the operation.

                                            The operators are also classified on the basis of their types of operation :

1. Arithmetical Operators
2. Relational Operators
3. Logical Operators
4. Bitwise Operators
5. Assignment Operator
6. Compound Assignment Operator (Short Hand Operator)


1. Arithmetical Operators : These operators are required for arithmetical calculations. They are of two types :


1. Binary Operators : The table given below lists all binary form arithmetical operators in Java :

Operator
Description
Function
Example
+
Plus
Adds the operands
a+b
-
Minus
Subtracts the operands
a-b
*
Multiply
Multiplies the operands
a*b
/
Divide
Divides the operands
a/b
%
Modulus (Remainder)
Finds the remainder when one number is divided by the other
a%b

2. Unary Operators : Operators + and - have a unary form too, in addition to binary forms. They are illustrated along with their functions in the table given below :

Operator
Description
Example
+
Promotes a to int if it’s a byte, short, or char
+a
-
Arithmetically negates a
-a

                                            The operators ++ and -- are the two shortcut arithmetic operators. They are used as follows :
1. x++ stands for x=x+1.
2. x-- stands for x=x-1.
                                            They have two versions :

1. The Prefix version : Increments/decrements the value of the operand by 1 before doing the operation with it.
1. The Postfix version : Increments/decrements the value of the operand by 1 after doing the operation with it.
                                            The table given below shows these operators :

Operator
Description
Example
++
Increments a by 1 after performing the operation with it
a++
++
Increments a by 1 before performing the operation with it
++a
--
Decrements a by 1 after performing the operation with it
a--
--
Decrements a by 1 before performing the operation with it
--a

2. Relational Operators : The relational operators in Java are used to compare the values of two operands a and b and results in the outcome of a boolean value. These are given in the table below :

Operator
Description
Example
> 
Greater than
a>b
< 
Less than
a<b
>=
Greater then equal to
a>=b
<=
Less than equal to
a<=b
= =
Equal to
a= =b
!=
Not equal to
a!=b

3. Logical Operators : These operators in Java are used to return a boolean value from an expression containing two or more comparisons. Java supports six logical operators, out of which five are binary and one is unary. The table belows shows these operators :


Operator
Description
Example
&&
Short-circuit or conditional AND
a&&b
||
Short-circuit or conditional OR
a||b
!
Logical NOT
!a
&
Logical AND
a&b
|
Logical OR
a|b
^
Logical XOR (exclusive OR)
a^b

5. Assignment Operator : The assignment operator = is used to assign value to a variable or to initialize them. For example :

int a=10;
float b=99.99;

6. Compound Assignment Operator (Short Hand Operator) : These operators are just like a shortcut assignment operator. They are given in the table below :

Compound Assignment Operator
Arithmetic Operator
a+=b
a=a+b
a-=b
a=a-b
a*=b
a=a*b
a/=b
a=a/b

13 comments:

  1. It is really a great work and the way in which u r sharing the knowledge is excellent.Thanks for helping me to understand basic concepts. As a beginner in java programming your post help me a lot.Thanks for your informative article.java training in chennai | chennai's no.1 java training in chennai

    ReplyDelete
  2. perfect explanation about java programming .its very useful.thanks for your valuable information.java training in chennai | java training in velachery

    ReplyDelete
  3. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.
    Click here:
    angularjs training in btm
    angularjs training in rajajinagar |angularjs training in marathahalli

    ReplyDelete
  4. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. In fact your creative writing abilities has inspired me to start my own BlogEngine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it.
    Click here:
    Microsoft azure training in velarchery
    Click here:
    Microsoft azure training in sollinganallur

    ReplyDelete
  5. The knowledge of technology you have been sharing thorough this post is very much helpful to develop new idea. here by i also want to share this.
    Devops training in sholinganallur

    ReplyDelete
  6. A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.

    rpa training in electronic-city | rpa training in btm | rpa training in marathahalli | rpa training in pune

    ReplyDelete
  7. I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favourites blog site list and will be checking back soon.

    Data Science Training in Chennai | Data Science training in anna nagar
    Data Science training in chennai | Data science training in Bangalore
    Data Science training in marathahalli | Data Science training in btm

    ReplyDelete
  8. Thank you for benefiting from time to focus on this kind of, I feel firmly about it and also really like comprehending far more with this particular subject matter. In case doable, when you get know-how, is it possible to thoughts modernizing your site together with far more details? It’s extremely useful to me.

    java training in tambaram | java training in velachery

    java training in omr | oracle training in chennai

    ReplyDelete

  9. Whoa! I’m enjoying the template/theme of this website. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and visual appeal. I must say you’ve done a very good job with this.

    Selenium Interview Questions and Answers

    Best Selenium Training in Chennai | Selenium Training Institute in Chennai | Besant Technologies

    Selenium Training in Bangalore | Best Selenium Training in Bangalore

    ReplyDelete
  10. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us. Do check | Get trained by an expert who will enrich you with the latest updates.
    German Classes in Chennai
    Java Training in Chennai
    best german classes in chennai
    German language training in chennai
    Java Classes in Chennai
    Core Java Training in Chennai

    ReplyDelete
  11. I likable the posts and offbeat format you've got here! I’d wish many thanks for sharing your expertise and also the time it took to post!!

    angularjs Training in chennai
    angularjs Training in chennai

    angularjs-Training in tambaram

    angularjs-Training in sholinganallur

    angularjs-Training in velachery

    ReplyDelete
  12. I accept there are numerous more pleasurable open doors ahead for people that took a gander at your site.we are providing ReactJs training in Chennai.
    For more details: ReactJs training in Velachery | ReactJs training in chennai

    ReplyDelete

ShareThis