3. Recap
• What is an array
• What is one dimensional array
• What is two dimensional array
3
4. Operators
• An operator performs an operation on data items
(also known as operands)
• Java operators can be classified as follows
• Arithmetic operators
• Relational operators
• Logical operators
4
6. Arithmetic Operators
• Java provides all the basic arithmetic operators
like + , - , * , / , %
• These can operate on any built in numeric data
types like any other languages
6
7. Contd..
Arithmetic Operators
• We can not use these operators on boolean data
type
eg. : These are used as
a+b , a-b , a*b , a/b , a% b
• Here a, b are variables or constants known as
operands
7
8. Relational Operators
• These operators are used for compare two
quantities
• Java supports the following relational operators
• < , <= , > , >= , = = , !=
• The value of the relational expression is either true
or false
8
9. Contd..
Relational Operators
• The syntax for relational operator is
Expression1 <relational operator> Expession2
• Here, Expression1 and Expression2 are arithmetic
expressions
9
10. Contd..
Relational Operators
• When arithmetic expressions are used , it must be
evaluated first and then results compared.
eg. : a<b
a<=b
a>b
a>=b
a= = b
a!=b
10
11. Logical Operators
• Java has three logical operators
&& - Logical AND
|| - Logical OR
! - Logical NOT
11
12. Contd..
Logical Operators
• An expression which combines two or more
relational expressions
• It is called as logical expression or compound
expression
eg. : a >b && c <d
• The logical expression given above is true only if
both conditions are true
• If either of them are false the expression is false
12
13. Assignment Operator
• These are used to assign the value of an
expression to a variable
• The assignment operator is ‘= ‘
13
14. Contd..
Assignment Operator
• These operators are used for shorthand assignment
in the following form
V op = value;
• Here, V is variable ,op is operator.
eg. : a+ = 9;
14
15. Contd..
Assignment Operator
• The above form is equivalent to
V = V op value;
eg. : a+ = 1 means a= a+1
15
16. Contd..
Assignment Operator
• Advantages of shorthand assignment operators are
• What appears on the left hand side need not be
repeated and therefore it becomes easier
• The statement is more easier to read
16
17. Increment/Decrement Operators
• Java has two useful operators
• These are increment(++) and decrement(--)
operators.
• The operator ++ adds one to the operand and the
operator -- subtracts one
17
18. Contd..
Increment/Decrement Operators
• Both are unary operators and these are in different
forms.
eg. : ++m or m++ ,this is equivalent to m+1
--m or m-- ,this is equivalent to m-1
18
19. Contd..
Increment/Decrement Operators
• The difference occurs only the operator is a part of
another expression
eg. : m = 9, k =++ m ;
• In this case the value of k would be 10
eg. : m = 9, k = m++ ;
• In this case the value of k would be 9 and m
would be 10
19
20. Conditional Operator
• The character pair ‘?:’ is a ternary operator
available in Java
• This operator is used to construct conditional
expressions of the form
Expression1 ? Expression2 : Expression3 ;
20
21. Contd..
Conditional Operator
• Here, ?: works as follows
• Expression1 is evaluated first if it is true
• Then the Expression2 is evaluated and becomes
the value of the conditional expression
21
22. Contd..
Conditional Operator
• If Expression1 is false, Expression3 is evaluated
• And its value becomes the value of the conditional
expression
eg. : x = (a > b ) ? a : b;
22
23. Bitwise Operators
• Java has a distinction of supporting special
operators known as ‘Bitwise Operators’
• These manipulate data at values of bit level
23
24. Contd..
Bitwise Operators
• These operators are used for testing the bits or
shifting them to the right or left
• Bitwise operators may not be applied to float or
double
24
25. Contd..
Bitwise Operators
• The bitwise operators are
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
~ Ones complement
<< Shift left
>> Shift right
>>> Shift right with zero fill
25
26. Special Operators
• Java supports some special operators
• Such as ‘ instanceOf ‘ operator
• And ‘Dot’ operator or member selection operators
26
27. instanceOf Operator
• The instanceOf operator is an object reference
operator
• It returns true if the object on the left hand side is
an instance of the class given on the right hand
side
27
28. Contd..
instanceOf Operator
• This operator allows us to determine the object
belongs to a particular class or not
eg. : s instanceof Student;
• The above statement is true if the object belongs
to the class Student
• Otherwise it is false
28
29. Dot Operator
• The Dot operator is used to access the instance of
variables and methods of a class
eg. : a.dispaly();
• It is also used to access classes and sub packages
from packages
29
32. Frequently Asked Questions
• List any Three Logical operator
• List any Four Bitwise Operators
• Explain various operators available in Java
32
33.
swings
Struts
jdbc
hibernate
home
java previous question papers
OCT/NOV-2012 QUESTION PAPER
April / May 2012 c-09
October/ November-2011 c-09
April/ May 2011 c-09
April/ May 2011 c-05
Home
33