Java Programing laungage

Core Java Tutorial

Introduction of Core Java

How To Install JDk and Set of Path

Syntax of java Program

Difference between Java and C/C++

Advantage and Disadvantage of Java

What is Java

Why Java is not Pure Object Oriented Language

Java has Following Features/Characteristics

Limitation of Java Language and Java Internet

Common Misconception about Java

Simple Program of Java

Integrated Development Environment in java

Compile and Run Java Program

Applet and Comments in Java

Tokens in Java

Keywords in Java

Identifier and Variables in Java

Literals/Constants

Data Type in Java

Assignments and Initialization in Java

Operators in Java

Rule of Precedence in Java

Operator on Integer and Separators in Java Programming

Java Control Flow of Statements

If and If-else Selection Statement

Nested If-else and If-else-If Selection Statement

switch case and conditional operator Selection Statement

for and while Loop

do..while and for each Loop

break and labeled break statement

continue and labeled continue statement

return Statement and exit() Method

Escape Sequence for Special Characters and Unicode Code

Constants and Block or Scope

Statement in Java

Conversions between Numeric Types in Java

Import Statement in Java

User Input in Java using Scanner Class

User Input in Java using Console Class

Array in Java

One Dimensional Array

Two Dimensional Array

Two Dimensional Array Program

Command Line Argument in Java

String args Types in Java

Uneven/Jagged array in java

Math Class Function and Constant

Math Class all Function used in a program

Enumerated Types in Java

Object Oriented Programming v/s Procedural Programming

Object Oriented Programming Concepts in Java

Introduction to Class,Object and Method in Java

Class Declaration in Java

Class & Objects in java

Encapsulation in Java

Modifiers/Visibility for a Class or Interrface or member of a Class

Polymorphism in Java

Runtime polymorphism (dynamic binding or method overriding)

adplus-dvertising
Operators in Java
Previous Home Next

Java provides a rich set of operators. Operators can be used to perform an action on one or two operands. An operator that can operate on one operand is as called unary oprator and an operator which can operate on two operands is called binary operator.

Java operators are divided in different categories.Assignment, increment and decrement, equality, arithmetic ,relational , logical, bit-wise, compound assignment, and conditional operator .

  1. Assignment operators( =,+=,-=,*=,/=,%=)
  2. Assignment operator is mainly used to assign value to the variables. This operator can also be used on objects to assign object references. These operators are same as in c/c++. It is represented by "=" symbol in Java which is used to assign a value to a variable lying to the left side of the assignment operator.

    This operator can also be used to assign the references to the objects.

    Syntax :

    <variable> = <expression>
    int i 4; 
    int j=8; //assignment operator = is used to assign the value to the variables 
    i, and j ,the values assigning are 4and 8 respectively. 
  3. Arithmetic operators are( +, - ,/, *, %)
  4. Arithmetic operators are used in mathematical expressions in the same way that they are used in algebra.

    int i=9;
    int j=0;
    int x;
    x= i+j; // operator is used to add the two integer values.
  5. Increment and Decrement Operators(++,--)
  6. Incrementing and Decrementing operators in Java Programming are (++ )and (- - )operators.In computer programming it is quite common to want to increase or decrease the value of an integer type by 1. Because of this Java provides the increment and decrement operators that add 1 to a variable and subtract 1 from a variable, respectively. The increment operator is denoted by two plus signs (++), and the decrement operator is denoted by two minus signs (--).

    variable++;
    ++variable;
    variable--;
    --variable;
    
    int a=5,b;
    
    b=++a*++a;
    
    System.out.println(b); //42
    
    a=5;
    
    System.out.print(++a*++a); //42
  7. Relational operators(<, > ,<= ,>=, instanceof)
  8. Relational Operators are important to any programming language to make comparisons between values. These operator are same as c or c++ but <,<=,>,>= can not be applied on boolean types and reference types.

    int x=10;
    int y=21;
    
    if(x>y) // relation check between x and y.
    {
            system .out.println ( "the greater no is:" + x);
    }
    else
    {
            system .out. println ("the greater no is :" + y);
    }  
  9. Equality operator(==,!=)
  10. These operator are same as c or c++.

    System.out.print(5==4); //false 
    System.out.print(5!=4); //true
  11. Logical operators(&&, | | , !.)
  12. NOT (!) - Performs the negation of a statement (True changed to false, false changes to true).

    AND (&&) - Performs the conjunction of two statements.

    OR (||) - Performs the disjunction of two statements.

    1. && is logical and:
    2. combines two boolean values and returns a boolean which is true if and only if both of its operands are true.

    3. || is logical OR:
    4. || combines two boolean variables or expressions and returns a result that is true if either or both of its operands are true.

    5. ! which means not:
    6. It reverses the value of a boolean expression. Thus if b is true !b is false. If b is false !b is true.

    These operator are same as c or c++.

    int a=5;
    if(a>5&&a++>5)
    {
      System.out.print("Hello");
    }
    else
    {
    	System.out.print("Bye");
    }
    	 System.out.print(a);

    output :

    Bye
  13. Conditional operators (?)
  14. These operator are same as c or c++.

    int x = 8;
    int y = 9;
    
    if (x== 1) && (y==2) 
    {
            system .out.println ("the value of x is 8 AND value of y is 9");
    }
  15. Bitwis operator(&,|,^,~,<<,>>>>)
  16. The Java programming language also provides operators that perform bitwise and bit shift operations on integral types. The unary bitwise complement operator "~"convert a bit pattern. It can be applied to any of the integral types, making every "0" a "1" and every "1" a "0".

    Example:

    a value whose bit pattern is "00000000" would change its pattern to "11111111".

    The signed left shift operator "<<" shifts a bit pattern to the left,and the signed right shift operator ">>" shifts a bit pattern to the right. The bit pattern is given by the left-hand operand, and the number of positions to shift by the right-hand operand. The unsigned right shift operator ">>>" shifts a zero into the leftmost position, while the leftmost position after ">>" depends on sign extension.

    The bitwise & operator performs a bitwise AND operation.

    The bitwise ^ operator performs a bitwise exclusive OR operation.

    The bitwise | operator performs a bitwise inclusive OR operation

    ~ Unary bitwise complement

    << Signed left shift

    >> Signed right shift

    >>> Unsigned right shift

    & Bitwise AND

    ^ Bitwise exclusive OR

    | Bitwise inclusive OR

Previous Home Next