OPERATORS
By
S. Shiyamala
P18260067
MEANING
An operator is a symbol that tells the
compiler to perform specific mathematical or
logical manipulations.
It is use to perform various operations on
Variables and Constants
Arithmetic
Unary
Assignment
Relational
Logical
Ternary
Bitwise
Shift
Arithmetic Operator
Arithmetic Operators are the symbols that
represents mathematical operations between two
Variables of Constants
 Addition +
 Subtraction -
 Multiplication *
 Division /
 Modular Division %
Syntax:
Operand operator Operand
For E.g., a+b, 8*9
Example:
class Weather
{
public static void main(String[] arguments)
{
float fah = 86;
System.out.println(fah + " degrees Fahrenheit is ...");
fah = fah - 32;
fah = fah / 9;
fah = fah * 5;
System.out.println(fah + " degrees Celsiusn");
float cel = 33;
System.out.println(cel + " degrees Celsius is ...");
cel = cel * 9;
cel = cel / 5;
Add 32 to the answer
cel = cel + 32;
System.out.println(cel + " degrees Fahrenheit");
}
}
Output:
86.0 degrees Fahrenheit is ...
30.0 degrees Celsius
33.0 degrees Celsius is ...
91.4 degrees Fahrenheit
Unary Operator
Unary operator operates with only one
operand i.e. a single input
 Increment Operator
 Decrement Operator
Syntax:
++x, x++ Increment
--y, y-- Decrement
Example:
class operators
{
public static void main(String[] args)
{
int a = 20, b = 10, c = 0;
// a=b+++c is compiled as
// b++ +c
// a=b+c then b=b+1
a = b++ + c;
System.out.println("Value of a(b+c), "
+ " b(b+1), c = "
+ a + ", " + b
+ ", " + c);
}
}
Output:
Value of a(b+c), b(b+1), c = 10, 11, 0
Assignment Operator
Operates '=' is used for assignment, it takes the
right-hand side (called rvalue) and copy it into the left-
hand side (called lvalue). Assignment operator is the
only operator which can be overloaded but cannot be
inherited.
Syntax:
l value assignment r value
For E.g., sub1=85
Relational Operator
A relational Operator that tests or defines
some kind of relation between two entities.
 lesser than (<)
 greater than (>)
 less than or equal to (<=)
 greater than equal to (>=)
 equivalent (==)
 not equivalent (!=)
Logical Operator
Logical operator are typically used with
Boolean (Logical) values
 AND Operator (True - both true)
 OR Operator (True – one true)
 NOT Operator (False X True)
Syntax:
if (condition operator condition)
expression
else
expression
Conditional Operator
Conditional Operator is a ternary operator
takes three operands. It return true value otherwise
false value.
Symbols - ? :
Syntax:
(condition? True:False);
For E.g., (a=100?Yes:No);
Bitwise Operator
There are used to change individual bits into a
number. They work with only integral data types like
char, int and long and not with floating point values.
•Bitwise AND operators &
•Bitwise OR operator |
•And bitwise XOR operator ^
•And, bitwise NOT operator ~
Comma Operator
These operators are used to shift the bits of a
number left or right thereby multiplying or dividing
the number by two respectively. They can be used
when we have to multiply or divide a number by
two.
Left shift operator <<
Right shift operator >>
Unsigned Right shift operator >>>
Thank You

Operators

  • 1.
  • 2.
    MEANING An operator isa symbol that tells the compiler to perform specific mathematical or logical manipulations. It is use to perform various operations on Variables and Constants
  • 3.
  • 4.
    Arithmetic Operator Arithmetic Operatorsare the symbols that represents mathematical operations between two Variables of Constants  Addition +  Subtraction -  Multiplication *  Division /  Modular Division % Syntax: Operand operator Operand For E.g., a+b, 8*9
  • 5.
    Example: class Weather { public staticvoid main(String[] arguments) { float fah = 86; System.out.println(fah + " degrees Fahrenheit is ..."); fah = fah - 32; fah = fah / 9; fah = fah * 5; System.out.println(fah + " degrees Celsiusn"); float cel = 33; System.out.println(cel + " degrees Celsius is ..."); cel = cel * 9; cel = cel / 5; Add 32 to the answer cel = cel + 32; System.out.println(cel + " degrees Fahrenheit"); } } Output: 86.0 degrees Fahrenheit is ... 30.0 degrees Celsius 33.0 degrees Celsius is ... 91.4 degrees Fahrenheit
  • 6.
    Unary Operator Unary operatoroperates with only one operand i.e. a single input  Increment Operator  Decrement Operator Syntax: ++x, x++ Increment --y, y-- Decrement
  • 7.
    Example: class operators { public staticvoid main(String[] args) { int a = 20, b = 10, c = 0; // a=b+++c is compiled as // b++ +c // a=b+c then b=b+1 a = b++ + c; System.out.println("Value of a(b+c), " + " b(b+1), c = " + a + ", " + b + ", " + c); } } Output: Value of a(b+c), b(b+1), c = 10, 11, 0
  • 8.
    Assignment Operator Operates '='is used for assignment, it takes the right-hand side (called rvalue) and copy it into the left- hand side (called lvalue). Assignment operator is the only operator which can be overloaded but cannot be inherited. Syntax: l value assignment r value For E.g., sub1=85
  • 9.
    Relational Operator A relationalOperator that tests or defines some kind of relation between two entities.  lesser than (<)  greater than (>)  less than or equal to (<=)  greater than equal to (>=)  equivalent (==)  not equivalent (!=)
  • 10.
    Logical Operator Logical operatorare typically used with Boolean (Logical) values  AND Operator (True - both true)  OR Operator (True – one true)  NOT Operator (False X True) Syntax: if (condition operator condition) expression else expression
  • 11.
    Conditional Operator Conditional Operatoris a ternary operator takes three operands. It return true value otherwise false value. Symbols - ? : Syntax: (condition? True:False); For E.g., (a=100?Yes:No);
  • 12.
    Bitwise Operator There areused to change individual bits into a number. They work with only integral data types like char, int and long and not with floating point values. •Bitwise AND operators & •Bitwise OR operator | •And bitwise XOR operator ^ •And, bitwise NOT operator ~
  • 13.
    Comma Operator These operatorsare used to shift the bits of a number left or right thereby multiplying or dividing the number by two respectively. They can be used when we have to multiply or divide a number by two. Left shift operator << Right shift operator >> Unsigned Right shift operator >>>
  • 14.