Operators


Operators are used to perform operations on variables and values. The value is called an operand, while the operation (to be performed between the two operands) is defined by an operator. Java divides the operators into the following groups:
  • Arithmetic operators,
  • Assignment operators,
  • Comparison operators,
  • Logical operators, and
  • Bitwise operators.
Arithmetic Operators
Arithmetic operators are used to perform common mathematical operations.

Operator Name Description Example
+ Addition Adds together two values. x + y
- Subtraction Substracts one value from another. x - y
* Multiplication Multiplies two values. x * y
/ Division Divides one value from another. x / y
% Modulus Returns the division remainder. x % y
++ Increment Increases the value of a variable by 1. ++x
-- Decrement Decreases the value of a variable by 1. --x

ArithOp.java (arithmetic operators)

  public class ArithOp {
    public static void main( String[ ] args ) {     
      double d1 = ;
      double d2 = ;
      System.out.println( d1--  ++d2 );
    }
  }
Output:        




      “The unexamined life is not worth living.”    
      ― Socrates