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 :-
The arithmetic operators -, +, * and / can be used to perform respectively subtraction, addition, multiplication and division with integers and reals.
2 int result = 3 * 56;
double answer = 3.14 + 2.72;
The logic operators &&, ||, ! and ^ can be used to perform respectively logical and, or, not and exclusive-or on boolean operands.
2 System.out.println(true || false); /* outputs true */
System.out.println(! true); /* outputs false */
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.
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... [continues]
Cite This Essay
(2012, 04). Explain Various Operator in Java, Also Comment How They Are Different from C++.. StudyMode.com. Retrieved 04, 2012, from http://www.studymode.com/essays/Explain-Various-Operator-In-Java-Also-969236.html
"Explain Various Operator in Java, Also Comment How They Are Different from C++." StudyMode.com. 04 2012. 2012. 04 2012 <http://www.studymode.com/essays/Explain-Various-Operator-In-Java-Also-969236.html>.
- MLA 7
"Explain Various Operator in Java, Also Comment How They Are Different from C++.." StudyMode.com. StudyMode.com, 04 2012. Web. 04 2012. <http://www.studymode.com/essays/Explain-Various-Operator-In-Java-Also-969236.html>.
"Explain Various Operator in Java, Also Comment How They Are Different from C++.." StudyMode.com. 04, 2012. Accessed 04, 2012. http://www.studymode.com/essays/Explain-Various-Operator-In-Java-Also-969236.html.