Professional Documents
Culture Documents
Variable is a name of memory location. There are three types of variables in java:
local, instance and static.
Example:
int a=10;
int a=10.5;
boolean b=0;
Note: In java, every variable and expression has some type, every assignment should
be checked by compiler for type compatibility, because of this reason Java language
is Strongly-Typed programming language.
Operators in java
Operator in java is a symbol that is used to perform operations. For example: +, -,
*, / etc.
There are many types of operators in java which are given below:
Unary Operator,
Arithmetic Operator,
shift Operator,
Relational Operator,
Bitwise Operator,
Logical Operator,
Ternary Operator and
Assignment Operator.
Operator
Category Precedence
Type
postfix expr++ expr--
Unary
prefix ++expr --expr +expr -expr ~ !
multiplicative */%
Arithmetic
additive +-
Shift shift << >> >>>
comparison < > <= >= instanceof
Relational
equality == !=
bitwise AND &
Bitwise bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
Logical
logical OR ||
Examples:
class Arith
{
public static void main(String args[])
{
int a=20,b=3;
System.out.println("Value of a is:"+a +"\nValue of b is:"+b);
System.out.println("Sum is:"+ (a+b));
System.out.println("Difference is:"+ (a-b));
System.out.println("Multiplication is:"+ (a*b));
System.out.println("Division is:"+ (a/b));
System.out.println("Remainder is:"+ (a%b));
}
}