Saturday, July 9, 2011

Introduction to operators in java

Operators in java are similar to c++ and c.
Operators are actions that manipulate, combine or compare variables.
They fall into several categories as follows:
OperatorsSymbols
Assignment+= -= *= \= %=
Arithmetic+ - * / % (modulus)
++ (increment) -- (decrement)
String Concatenation+
Comparison or Relational Operators== , != , > , >= , < <=
Logical OR Boolean Comparison! & | ^ && || (&& are short circuit ops)
Bitwise Comparison~ & | ^ (xor) << >> >>>
Bitwise Assignment&= |= ^= (xor) <<= >>= >>>=
Conditional operator? (eg (expr1) ? expr2 : expr3 )
Object Creationnew (eg int a[] = new int[10];)
Class of Objectinstanceof
Casting of Type(var_type)

Note: Changes in data type are done explicitly using a cast operation. For examplea = (int) b; assumes a is of type int and b is of another type.

Number of Operands for Operators

Java operators can be classified as unary, binary, or ternary—meaning taking one, two, or three arguments, respectively. A unary operator may appear
before (prefix) its argument or after (postfix) its argument. A binary or ternary operator appears between its arguments.

No comments:

Post a Comment

Chitika