Explain Various Operator in Java, Also Comment How They Are Diffe...

Continues for 4 more pages »
Read full document

Explain Various Operator in Java, Also Comment How They Are Different from C++.

By | April 2012
Page 1 of 5
explain various operator in java, also comment how they are different from c++. Operators
After having seen the basic types in Java and how to declare variables of each type, we are now going to show what basic operations can be performed with and on variables of the basic types. Below is a table summarizing Java operators organized by the type of operation the operator is used for. There are 8 types of operator that is follow :-

1 )- Arithmetic Operators
2)- Logic Operators
3)- Bitwise Operators
4)- Assignment Operators
5)- The Conditional Operators
6)- Increment and decrement operators
7)- Special operator
8)- Relational operator

Description of these operators :-
Arithmetic Operators
The arithmetic operators -, +, * and / can be used to perform respectively subtraction, addition, multiplication and division with integers and reals. Example :-
1
2int result = 3 * 56;
double answer = 3.14 + 2.72;
Logic Operators
The logic operators &&, ||, ! and ^ can be used to perform respectively logical and, or, not and exclusive-or on boolean operands. Example:
1
2System.out.println(true || false); /* outputs true */ System.out.println(! true); /* outputs false */
Bitwise Operators
The bitwise operators &, |, ^, ~, and >>> can be used to perform bitwise and, or, exclusive-or, negation, left shift and right shift on integer operands. Note that there are two types of right shift: >> and >>>. The difference being that >> copies the sign bit into the high-order positions and >>> copies zeros into the high-order positions. Example:

1
2System.out.println(12 & 5); /* outputs 4 because 1100 & 0101 = 0100 = 4 */ System.out.println(3 >= all require a location (a variable) on the left side and an expression of the same type (or one that could be promoted to the same type) on the right side. The basic assignment operator = evaluates the expression on the right and stores the resulting value in the location on the left....

Rate this document

What do you think about the quality of this document?

Share this document

Let your classmates know about this document and more at Studymode.com