Skip to main content

JAVA: Operators.

JAVA.

    Do you wanted to know what is operator? what are the types of operator? to know that read the following carefully and completely to understand.

OPERATORS.

Operators are Tokens, unit of instruction.

An operator is a symbol that tells the computer to perform certain mathematical and logical manipulation.

Operator is used in program to manipulate data or variable.

There are 8 types of operator
  1. Arithmetic operator.
  2. Relational operator.
  3. Logical operator.
  4. Assignment operator. 
  5. Increment and Decrement operator.
  6. Conditional operator.
  7. Bitwise operator.
  8. Special operator
Arithmetic operator.

            Arithmetic operator are used to construct mathematical expressions. Java support 5 arithmetic operator.

 Operator Description
        +
        -
        *
        /
        %
 Addition
Subtraction
multiplication
division
remainder

example:
x=8, y=2
 Operator result
       x+y
       x-y
       x*y
       x/y
       x%y
10
6
16
4
0



Relational operator.

The relational operator are used to form relational expression.

The result of the relational expression is boolean value either true or false.

Java support 6 relational operator.

 Operator Description
        >
       <
       >=
      <=
      ==
      !=
Greater than
lesser than
grater than or equal to
lesser than or equal to
equal to
not equal to

example:
x=5, y=2
 Operator Result
      x>y
      x<y
      x>=y
      x<=y
      x==y
      x!=y
true
false
true
false
false
true


Logical Operators.

Logical operators are used to combine two or more relational expressions.

It is also known as compound relational expression.

The result of the logical expression is boolean value either true or false.

 Operator Description
        !
     &&
       ||
Logical NOT.
Logical AND.
Logical OR.

Example:
 Operator Result
(x==8)&&(y>=3)
(x==5)||(y>=4)
!(x<=5)
true.
false.
true.


Assignment operator.

        The assignment operator'=' is used to assign the value of avariable, constant or expression to a variable.

Syntax:
            variable operator=value or expression;

example:
            x=y+5;
            x=10:


Increment and decrement operator.

It is a unary operator which operates on a signal operator.

Increment operator(++) is used to increment the value of a variable by 1.

Decrement operator(--) is used to decrement the value of a variable by 1.
  • Prefix increment and decrement operator = when this operator is used with a variable. first, it is incremented by 1 and then expression is evaluateded
                example:
                            x=10                    x=10
                            y=++x                 y=--x
            output:    x=11                    x=9
  • Post-fix increment and decrement operator = when this operator is used with a variable. first, the expression is evaluated and then incremented by 1.
                example:
                            x=10                    x=10
                            y=x++                y=x--
            output:    x=11                    x=9



Conditional operators.

       A Conditional operator is also called Ternary operator. It is similar to if-else operator but, it takes less space and easy to read than if-else statement.
  
   syntax:
       variable= expression1? expression2: expression3;
   
   working :
          expression1 is considered to be the condition, if the condition is true, expression2 is executed and result is found, if the condition is false expression3 is executed and result is found.

    example:
             int x=5, y=10, z;
             z=(x>y)?x:y;
   output:  z=10.


Bitwise operator.

        Bitwise operator are used for controlling and intreaction with hardware and also for manipulating data at the bit level.

There are six bitwise operators.

 Operator Description
      &
       |
      ^
      ~
    <<
    >>
   >>>
   <<=
   >>=
 >>>=
Bitwise AND
Bitwise OR.
Bitwise Ex-OR.
One's complement
left shift
Right shift.
Zero fill right shift
Left shift assignment.
Right shift assignment.
Zero fill right shift assignment.

Example:
x=4, y=5
 Operator Description
      x&y
       x|y
      x^y
      ~x
    x<<2
    x>>2
   x<<=2
   x>>=2
        4
        5
        1
       -5
       16
        1
       16
        1



Special Operators.

Java support special operator like...

 operator description
        ,
        .
 instanceof 
 Comma operator
Dot operator
Object is an instance.





Check out the interesting history of Java.

The important features of java.

The structure of java.

The environment of java.

Also the complete process to execute java program.

check out other tokens:

                identifier.
               keywords.
               constants.
               datatypes.
                variables.
                separator.

Comments