Operators are such symbols that perform some operations on one or more operands. Operators are used to manipulate primitive data types.
Operators and Expressions
Operators:
Operators are such symbols that perform some
operations on one or more operands. Operators are used to
manipulate primitive data types. Once we declare and initialize the variables, we can
use operators to perform certain tasks like assigning a value, adding the
numbers etc.
Java operators can be classified into different categories as shown:
- Simple Assignment Operators
- Arithmetic Operators
- Unary Operators
- Equality and Relational Operators
- Conditional (Logical) Operators
- Bitwise and Bit Shift Operators
Expressions:
In Java, an expression is like a statement without a
terminator ( i.e. statement = expression + ; ). It
is made up of variables, operators, and method invocations, which are
defined in accordance to the syntax of the language. The overall coding in a Java
program is achieved through the expressions ( which may have single or multiple operations)
. In all cases, a single evaluated value is obtained irrespective of composition
of the multiple expressions. The evaluation of an expressions is determined by
the order of precedence of the operators.
Few of the examples of expressions are:
int number = 2
arr[0] = 10
int abc = a + (++b)* ((c / a)*
b)
System.out.println("Hi,How are
you") //
a compound expression
After executing an expression, a value
is returned by an expression, it's data type depends on the elements used in
the expression
Java also allows you to build the compound expression.
There are three purposes for defining an expression :
- To compute values.
- To assign values to variables.
- To control the flow of execution.