You are on page 1of 7

Operators

23 December 2020 20:01

4.Logical Operator's Ternary Operator

Used to determine logic between variable/values. Only conditional operator that takes 3 operands.
Its and replacement for if-then-else

Symbol--> ? :

5.Java Bitwise Operators

Used to perform binary logic with bits of interger

Egs:-
num1 = 10;
num2 = 20;
res=(num1>num2) ? (num1+num2):(num1-num2)
Since num1<num2,
the second operation is performed
res = num1-num2 = -10

Notes Class X Page 1


Since num1<num2,
the second operation is performed
res = num1-num2 = -10

Notes Class X Page 2


Precedence of Operator
27 December 2020 04:22

Certain operators have higher precedence than others and therefore precedence of operator decides how an expression
should be evaluated.

Arithmetic > Relational > Logical

In Arithemtic:- BEDMAS rule is followed ( Bracket Exponent Division/Multiplication Addition/Subtraction


In Logical :- NAO rule ( NOT > AND >OR)

ICSE 2015

Notes Class X Page 3


PREFIX/INFIX/POSTFIX
28 December 2020 15:36

In an expression there are 2 things , operators and operands.

b + c ->
Here b and c are the operands and + is the operator.

Now we can put this + operator in 3 ways


1. +bc
2. b+c
3. bc+

Noticed how the operator was put at different locations but all means the same.

Infix:- If the operator is between the operands in the expression.


b+c
Prefix:- If the operator is before the operands in the expression.
+bc
Postfix:- If the operator is after the operands in the expression.
Bc+

Notes Class X Page 4


Increment & Decrement operator
28 December 2020 15:42

Both preorder and postorder do the same thing that is


Earlier we have seen the ++ and -- operator. increase(++) or decrease (--) the value of variable by 1.
But there is a slight difference.
These operator can also be put as post-order or pre-order
In post-order expression, the variable is first used and then
POST ORDER increased.
In pre-order expression , the variable is first increased and then
a-- decreased.

PRE ORDER

++a

Notes Class X Page 5


Type Casting
28 December 2020 16:01

Conversion of one type of data to another Implicit Casting :- Explicit Casting :-


It is of 2 type 1. done automatically by the compiler 1. Done forcefully by the user
1. Implicit 2. Lower data type to higher data type 2. Higher data type to lower data type
2. Explicit 3. Loss of data is not there 3. Loss of data is there

Implicit
byte -> short -> char -> int -> long -> float -> double

Explicit
double -> float -> long -> int -> char -> short -> byte

Egs:-

double a=45.5;
int b=(int)a; --> 45

double a=45;

int a='A';

Notes Class X Page 6


Mathematical functions
28 December 2020 16:10

Packages are a way to encapsulate a group of classes together.


Some packages in java are:-

Java.lang package contains all the functions for mathematical operation.

Notes Class X Page 7

You might also like