Java Operators

         Java supports rich set of operators. we have already used several of them such as = , +, -, and * . an operator is a symbol that tells a computer to perform certain mathematical or logical manipulations. Operators are used in programs to manipulate data and variables. Java operators can be classified into

 1.  Arithmetic operators 

2. Relational Operators 

3. Logical Operators 

4. Assignment Operators 

5. Increment and Decrement operators 

6. Conditional Operators 

7. Bitwise operators 

8. Special operators. 

1.  Arithmetic operators 

        Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra. Java provides all the basic arithmetic operations.The following table lists the arithmetic operators:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
  • Modulus (%)

 program : 01


output:01


2. Relational Operators

  • Equal to (= =)
  • Not equal to (!=)
  • Greater than (>)
  • Less than (<)
  • Greater than or equal to (>=)
  • Less than or equal to (<=)

program : 02


 

output:02


3. Logical Operators 

        Java has three logical operators. The logical operators && and || are used when we want to form compound condition by combining two or more relations. An example is: a>b && x==10 An expression of this kind which combines two or more relational expressions is termed as logical expression or a compound relational expression. A logical expression also yields a value of true or false according to the truth table.

  • Logical AND ( && )
  • Logical OR ( || )
  • Logical NOT ( ! )

Truth table 

Op-1         Op-2         Op1&&op-2         Op-1||op2 

True          True             True                     true 

True          False            False                    true 

False         True             False                    true 

False         False            False                   false

program : 03

output:03

4. Assignment Operators

  •  Assignment (=)
  •  Compound Assignment Operators (e.g., +=, -=, *=, /=, %=)

 program : 04


output:04

5. Increment and Decrement operators

  •  Increment (++)
  •  Decrement (--)

program : 05

output:05

6. Conditional Operators

  •  (condition) ? expression1 : expression2

program : 06

output:06


7. Bitwise operators

  • Bitwise AND (&)
  • Bitwise OR (|)
  • Bitwise XOR (^)
  • Bitwise NOT (~)
  • Left Shift (<<)
  • Right Shift (>>)
  • Unsigned Right Shift (>>>)

program : 07

output:07

8. Special operators.

        Java supports some special operators of interest such as instance of operator and member selection operator(.)

 

 

 

 

 

 

 

 

 

Comments

Popular posts from this blog

digital marketing ppt-u1

SOFTWARE

cn lab

Computer Operations and Performing - D L Unit-1-1

DBMS Degree Lab Records

DS-Record-mca-04) write a program for evaluating a given postfix expression using stack.

Java unit-1 history , C++ vs Java , java environment

Access the Internet to Browse Infromation & E-Mail Operation- D L Unit-2-1

OAT-Record-01) Visiting card

java program structure,java Tokens, keywords,