KEMBAR78
Operators in java | PPTX
Operators in JAVA ..
OPERATOR
 An operator is a symbol that operates on one or
more arguments to produce a result.
 Java provides a rich set of operators to
manipulate variables
OPERANDS
 An operands are the values on which the operators act upon.
 An operand can be:
 -> A numeric variable - integer, floating point or character
 -> Any primitive type variable - numeric and boolean
 -> Reference variable to an object
 -> A literal - numeric value, boolean value, or string.
-> An array element, "a[2]“
-> char primitive, which in numeric operations is treated
as an unsigned two byte integer
TYPES OF OPERATORS
 1. Assignment Operators
 2. Increment Decrement Operators
 3. Arithmetic Operators
 4. Bitwise Operators
 5. Relational Operators
 6. Logical Operators
 7. Ternary Operators
 8. Comma Operators
 9. Instanceof Operators
ASSIGNMENT OPERATORS
 The assignment statements has the following syntax :
<variable>=<expression>
 Assigning primitive value
int a, b;
a = 2; // 2 is assigned to variable a
b = 5; // 5 is assigned to variable b
Assigning references
Home home1 = new Home(); //new object created
Home home2 = home1; //assigning the reference of home1 in home2
ASSIGNING VALUES EXAMPLE
INCREMENT AND DECREMENT OPERATORS
++ AND --
 The increment and decrement operators add an integer
variable by one.
 increment operator:
 two successive plus signs, ++
 decrement operator: --
Common Shorthand
a = a + 1; a++; or ++a;
a = a - 1; a--; or --a
EXAMPLE OF ++ AND -- OPERATORS
ARITHMETIC OPERATORS
 The arithmetic operators are used to construct mathematical expressions as
in algebra.
 Their operands are of numeric type.
SIMPLE ARITHMETIC
BITWISE OPERATORS
 Java's bitwise operators operate on individual bits
of integer (int and long) values.
 If an operand is shorter than an int, it is
promoted to int before doing the operations.
BITWISE OPERATORS
EXAMPLE OF BITWISE OPERATORS
EXAMPLE CONT.,
RELATIONAL OPERATORS
 A relational operator compares two values and
determines the relationship between them.
 For example, != returns true if its two operands are
unequal.
 Relational operators are used to test whether two values
are equal, whether one value is greater than another, and
so forth
EXAMPLE OF RELATIONAL OPERATORS
LOGICAL OPERATORS
 These logical operators work only on boolean operands. Their return values
are always boolean.
EXAMPLE OF LOGICAL OPERATORS
TERNARY OPERATORS
 Java has a short hand way by using ?: the ternary aka conditional operator
for doing ifs that compute a value.
 Unlike the if statement, the conditional operator is an expression which can
be used for
COMMA OPERATORS
 Java has an often look past feature within it’s for loop
and this is the comma operator.
 Usually when people think about commas in the java
language they think of a way to split up arguments within
a functions parameters
EXAMPLE OF COMMA OPERATOR
INSTANCEOF OPERATORS
 This operator is used only for object reference variables. The
operator checks whether the object is of a particular type(class type
or interface type).
 InstanceOf operator is wrriten as:
EXAMPLE OF INSTANCEOF OPERATOR
Operators in java

Operators in java

  • 1.
  • 2.
    OPERATOR  An operatoris a symbol that operates on one or more arguments to produce a result.  Java provides a rich set of operators to manipulate variables
  • 3.
    OPERANDS  An operandsare the values on which the operators act upon.  An operand can be:  -> A numeric variable - integer, floating point or character  -> Any primitive type variable - numeric and boolean  -> Reference variable to an object  -> A literal - numeric value, boolean value, or string. -> An array element, "a[2]“ -> char primitive, which in numeric operations is treated as an unsigned two byte integer
  • 4.
    TYPES OF OPERATORS 1. Assignment Operators  2. Increment Decrement Operators  3. Arithmetic Operators  4. Bitwise Operators  5. Relational Operators  6. Logical Operators  7. Ternary Operators  8. Comma Operators  9. Instanceof Operators
  • 5.
    ASSIGNMENT OPERATORS  Theassignment statements has the following syntax : <variable>=<expression>  Assigning primitive value int a, b; a = 2; // 2 is assigned to variable a b = 5; // 5 is assigned to variable b Assigning references Home home1 = new Home(); //new object created Home home2 = home1; //assigning the reference of home1 in home2 ASSIGNING VALUES EXAMPLE
  • 6.
    INCREMENT AND DECREMENTOPERATORS ++ AND --  The increment and decrement operators add an integer variable by one.  increment operator:  two successive plus signs, ++  decrement operator: -- Common Shorthand a = a + 1; a++; or ++a; a = a - 1; a--; or --a
  • 7.
    EXAMPLE OF ++AND -- OPERATORS
  • 8.
    ARITHMETIC OPERATORS  Thearithmetic operators are used to construct mathematical expressions as in algebra.  Their operands are of numeric type.
  • 9.
  • 10.
    BITWISE OPERATORS  Java'sbitwise operators operate on individual bits of integer (int and long) values.  If an operand is shorter than an int, it is promoted to int before doing the operations.
  • 11.
  • 12.
  • 13.
  • 14.
    RELATIONAL OPERATORS  Arelational operator compares two values and determines the relationship between them.  For example, != returns true if its two operands are unequal.  Relational operators are used to test whether two values are equal, whether one value is greater than another, and so forth
  • 16.
  • 17.
    LOGICAL OPERATORS  Theselogical operators work only on boolean operands. Their return values are always boolean.
  • 18.
  • 19.
    TERNARY OPERATORS  Javahas a short hand way by using ?: the ternary aka conditional operator for doing ifs that compute a value.  Unlike the if statement, the conditional operator is an expression which can be used for
  • 20.
    COMMA OPERATORS  Javahas an often look past feature within it’s for loop and this is the comma operator.  Usually when people think about commas in the java language they think of a way to split up arguments within a functions parameters
  • 21.
  • 22.
    INSTANCEOF OPERATORS  Thisoperator is used only for object reference variables. The operator checks whether the object is of a particular type(class type or interface type).  InstanceOf operator is wrriten as:
  • 23.