Friday 10, February 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    Forum    |    About Us    |    Contact Us

Java Operators

Operators are used to manipulate primitive data types. In Java, there are six categories of operators.

 

Assignment Operator:

Assignment operator is the most common operator almost used with all programming languages. 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.

 

x=y+z;

 

Arithmetic Operators:

Arithmetic Operators are used to perform some mathematical operations like addition, subtraction, multiplication, division, and etc.

 

Symbol
Operator Name
Example
 +
Additive Operator 
 n =  n + 1;
 -
Subtraction Operator
 n =  n - 1;
 *
Multiplication Operator 
 n =  n * 1;
 /
Division Operator
 n = n / 1;
 %
Remainder Operator
 n = n % 1;

 

 

Unary Operators:

The unary operators require only one operand to perform different kind of operations such as increasing/decreasing, negating an expression, or inverting a boolean value.

 

Symbol
Operator Name
Operation
 +  
 Unary plus operator
 indicates positive value (however, numbers are positive without this)
 - 
 Unary minus operator
 negates an expression
 ++  
 Increment operator
 increments a value by 1
 --  
 Decrement operator
 decrements a value by 1
 !  
 Logical compliment operator
 inverts a boolean value

 


Equality and Relational Operators:
Equality and relational operators are used to compare the results of two expressions or operands in a program to know whether an operand is equal, not equal, greater than, less than to another operand.

 

Symbol
Operator Name
Example
 = =
Equal to
 a = = b
 !=
Not equal to
 a ! = b
 >  
Greater than
 a > b
 <
 Less than
 a < b
 >= 
Greater than or equal to
 a > = b
 <=  
Less than or equal to
 a > = b
 
Conditional or Logical Operators:
Conditional operators return a true or a false value based on the state of the variables i.e. the operations using conditional operators are performed between the two boolean expressions.

 

Symbol
Operator Name
 &
AND
 &&
Conditional-AND
 |
OR
 || 
Conditional-OR
 !
NOT
 ? :  
Ternary (shorthand for if-then-else statement)
 
Bitwise and Bit Shift Operators:

The bitwise and bit shift operators are used to manipulate the contents of variables at a bit level according to binary format. These operators perform bitwise and bit shift operations on integral type variables.

 

Symbol
Operator Name
Example
 ~  
Unary bitwise complement
~op2
 &
Bitwise AND
op1 & op2
 | 
Bitwise inclusive OR
op1 | op2
 ^  
Bitwise exclusive OR
op1 ^ op2
 << 
Signed left shift
op1 << op2
 >>
Signed right sift
op1 >> op2
 >>>
Unsigned right shift
op1 >>> op2
 
Type Operators :
instanceof is a run-time operator used to compare a class and an instance of that class. This operator " instanceof" compares an object to a specified class type.
The instanceof operator is defined to know about an object's relationship with a class. It evaluates to true, if the object or array is an instance of the specified type; otherwise it returns false.

 

Operator Precedence  
When two operators share an operand then operator with the higher precedence gets evaluated first. However, if the operators  have the equal precedence in the same expression then that  expression will be evaluated from left to right except the assignment operators.

 

Precedence
Operator
Type
Associativity

15

()
[]
·

Parentheses

Array Subscript

Member selection

Left to Right

14

++
--

Unary post-increment

Unary post-decrement

Right to left

13

++
--
+
-
!
~
( type )

Unary pre-increment

Unary pre-decrement

Unary plus

Unary minus

Unary logical negation

Unary bitwise complement

Unary type cast

Right to left

12

*
/
%

Multiplication

Division

Modulus

Left to right

11

+
-

Addition

Subtraction

Left to right

10

<<
>>
>>>

Bitwise left shift

Bitwise right shift with sign extension

Bitwise right shift with zero extension

Left to right

9

<
<=
>
>=
instanceof

Relational less than

Relational less than or equal

Relational greater than

Relational greater than or equal

Type comparison (objects only)

Left to right

8

==
!=

Relational is equal to

Relational is not equal to

Left to right

7

&

Bitwise AND

Left to right

6

^

Bitwise exclusive OR

Left to right

5

|

Bitwise inclusive OR

Left to right

4

&&

Logical AND

Left to right

3

||

Logical OR

Left to right

2

&:

Ternary conditional

Right to left

1

=
+=
-=
*=
/=
%=

Assignment

Addition assignment

Subtraction assignment

Multiplication assignment

Division assignment

Modulus assignment

Right to left

 
 
     
   
Java Language Tutorial
 
  What is JAVA
What is JAVA
  Java an Object Oriented Language
Java an Object Oriented Language
  Java Keywords
Java Keywords
  Data Types
Data Types
  Java Operators
Java Operators
  Control Structure
Control Structure
  Arrays
Arrays
  Java Classes
Java Classes
  Java Constructors
Java Constructors
  Java Methods
Java Methods
  Java Method Overloading
Java Method Overloading
  Java Method Overriding
Java Method Overriding
  Java Nested Classes
Java Nested Classes
  Inheritance in Java
Inheritance in Java
  Interfaces in Java
Interfaces in Java
  Polymorphism in Java
Polymorphism in Java
  Exception Handling in Java
Exception Handling in Java
  Catching Exceptions
Catching Exceptions
  Embedding information in an exception object
Embedding information in an exception object
  The throws clause
The throws clause
  Checked and unchecked exceptions
Checked and unchecked exceptions
  The finally clause
The finally clause
  Applets in Java
Applets in Java
  Running an Applet
Running an Applet
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download Online Videos Become Internets Most Valuable Player Ebook Online Videos Become Internets Most Valuable Player
   
Download Are You Ready Ebook Are You Ready
   
Download 	C Elements of Style Ebook C Elements of Style
   
Download Freebie guide Ebook Freebie guide
   
Download Importance of Search Engine Article and Directory Submission Ebook Importance of Search Engine Article and Directory Submission
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz