Java Reference
In-Depth Information
If expression 1 is true then expression 2 is evaluated and it becomes the resultant or final
value of the above given conditional statement.
If expression 1 is false then expression 3 is evaluated and it becomes the resultant or final
value of the above given conditional statement. Always remember, only one of the both
expression 2 and expression 3 is calculated depending of expression1's result.
p = 10;
q = 15;
r= ( p > q ) ? p : q ;
In the above given example, r is assigned the same value as q.
This operator behaves same as if-else. Above program in if-else
if(p>q)
r=p;
else
r=q;
Bitwise operators
Java provides a rich set of bitwise operators which operate on individual bits of an integer.
In case, operand is shorter than int then before applying bitwise operations that is converted
into int. These operators can't be applied to double or float.
Firstly an integer is represented in binary form and after that bitwise operators are applied
on the individual bits of the binary forms of the corresponding operands. For example 6 is
represented in binary as 110 . 2's complement is used for storing negative numbers.
public class Bitwise {
public static void main(String args[]) {
int p = 60;
/* Binary representation 60 = 0011 1100 */
int q = 13;
/* Binary representation 13 = 0000 1101 */
int r = 0;
r = p & q; /* Binary representation 12 = 0000 1100 */
System.out.println("p & q = " + r );
Search WWH ::

Custom Search