Lesson 4 - Operators in Java
Lesson 4 - Operators in Java
We now know …
• Character sets in JAVA
• UNICODE ,ASCII code
• Escape sequences
• Token and its types(keywords, literals, identifiers,
punctuators, operators)
• Variables (initialisation)[ Qs. how is static and dynamic
initialisation different?)
• Data types in JAVA(Qs. integers are primitive type or non
primitive type?)
• Type conversion(implicit, explicit)
Scope of this chapter
• Arithmetic expression , statement
• Operators(unary, binary, ternary)
• Increment, decrement, postfix, prefix
• New operator ,invoking members of class by dot operator
• Output statement
• Hierarchy of operators
Operators and Arithmetical expression
• A symbol or token performing arithmetical or logical operations ->gives meaningful
result
ARITHMETIC EXPRESSION
VARIABLES CONSTANTS
OPERATORS
x,y ,a,b +,-,*
2,15,4
• Relational operators : These show relation between the operands, such as true
or false
Relational operators in JAVA
• The program gives output according to condition
Logical operators
• Operators like AND ,OR , NOT are used as logic
• True or false output is given depending upon the outcome of
expressions
• Variable=(test expression)?Expression1:Expression2
Rewrite as ternary operator
• If (a>b)
{
d=(a-b);
else
d=(b-a);
}
Answer: d=(a>b)?(a-b): (b-a)