Studyon Minte9.com
Fundamentals (Docs)

Study

Operators



Operators are special symbols that perform specific operations on one, two, or three operands, and then return a result.

The Simple Assignment Operator ( = )

	int speed = 0;

The Arithmetic Operators

	int result = 1 + 2; // 3 (aditive operator)
	result= result - 1; // 2 (subtraction operator)
	result = result * 2; // 4 (multiplication operator)
	result = result / 2; // 2 (division operator)
	result = 10 % 7; // 3 (remainder operator)
	Compound assignment:
		int result = 1;
		result += 2; // 3
		result -= 1; // 2
		result *= 10; // 20
		result /= 2; // 10
		result %= 7; // 3

String concatenation

	String a = "b" + "c"; // "bc"

Unary operator

	int result = +1; //  1 (unary plus operator)
        result--;  //  0 (decrement operator)
        result++; // 1 (increment operator)
        result = -result; // -1 (unary minus operator)
	boolean success = false;
        System.out.println(!success); // true (logical complement operator)

Prefix/Postfix operator

The code result++; and ++result; will both end in result being incremented by one. 
The only difference is that the prefix version (++result) evaluates to the incremented value, 
whereas the postfix version (result++) evaluates to the original value.

	int i = 5;		   
	System.out.println(i);	// "5"
	System.out.println(++i);	// "6"
	System.out.println(i++);	// "6"
	System.out.println(i);	// "7"

The Equality and Relational Operators

	==      equal to
	!=      not equal to
	>       greater than
	>=      greater than or equal to
	<       less than
	<=      less than or equal to

The Conditional Operators

	&&	Conditional AND
	||	Conditional OR
	?:	ternary operator 

Type Comparision Operator instanceof

	class InstanceofDemo {
	    public static void main(String[] args) {
		Parent obj1 = new Parent();
		Parent obj2 = new Child();
		System.out.println(obj1 instanceof Parent); // true
		System.out.println(obj1 instanceof Child); // false
		System.out.println(obj1 instanceof MyInterface); // false
		System.out.println(obj2 instanceof Parent); // true
		System.out.println(obj2 instanceof Child); // true
		System.out.println(obj2 instanceof MyInterface); // true
	    }
	}
	class Parent{}
	class Child extends Parent implements MyInterface{}
	interface MyInterface{}


http://docs.oracle.com/javase/tutorial/java/nutsandbolts/operators.html