Preview

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

Powerful Essays
Open Document
Open Document
1312 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Explain Various Operator in Java, Also Comment How They Are Different from C++.
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
2 int 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
2 System.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
2 System.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

You May Also Find These Documents Helpful

Related Topics