Session 3- Working with Java Operators and Expressions … — Transcript

Learn about Java operators and expressions, including arithmetic, relational, logical, assignment, increment/decrement, and ternary operators with examples.

Key Takeaways

  • Operators are symbols that perform specific operations on operands (variables).
  • Java provides six main categories of operators for various programming needs.
  • Arithmetic operators work only on numeric data types like int, float, and double.
  • Assignment operators store values into variables and include shorthand forms.
  • Understanding operators is fundamental to writing effective Java expressions.

Summary

  • Introduction to Java operators as symbols that perform operations on variables.
  • Explanation of variables and operands in expressions.
  • Detailed overview of six main types of Java operators: arithmetic, relational/comparison, logical, increment/decrement, assignment, and conditional/ternary operators.
  • Examples of arithmetic operators: plus, minus, multiply, divide, and modulo.
  • Description of relational operators like greater than, less than, equal to, and not equal to.
  • Logical operators covered include AND, OR, and NOT.
  • Increment (++) and decrement (--) operators explained.
  • Assignment operators including shorthand forms like +=, -=, *=, /=, and %=.
  • Introduction to the ternary (conditional) operator using question mark and colon.
  • Practical demonstration of operators in Java code using Eclipse IDE.

Full Transcript — Download SRT & Markdown

00:04
Speaker A
All right, so in the previous class, we have seen how to work with variables and data types, how can we define the variables with the data types, and different types of data types we have seen. And in today's session, we will see operators. So what is basically operator means? Operator basically is a symbol which will perform certain operation or which will perform an operation. Okay, for example, let us say we'll have two different variables. Let's say int a = 10. This is one variable.
00:17
Speaker A
the today's session we will see operators so what is basically operator means operator uh basically a symbol which will perform certain operation or which will perform an operation okay for example uh let us say we'll have two different variable let's say in a = to 10 this is one variable
00:41
Speaker A
int b = 20. This is another variable. A is one variable, B is another variable. Both are having some data. Now if you want to add these two numbers, what we will do? Now we can say a + b. So when I say a plus b, this will add two numbers 10 + 20. Now once added, the result I will store in another variable. Here I will define one more variable, let's say int result like this. Now if I look at this particular simple code, a and b are called variables. A and B are called variables, and here a plus b is called an expression. Okay, a and plus b here we are calling as expression. So what plus is doing here? The plus is adding two numbers a and b, right? So which is basically called as an operator. Means an operator is a symbol which will perform an operation. That's a simple definition. Operator is a symbol which will perform an operation. There are multiple operators which we have.
00:55
Speaker A
A plus b this will add two numbers 10 + 20 now once added the result I will store in another variable here I will Define one more variable let's say int uh result like this now if I look
01:10
Speaker A
So plus is one of the operators. So here plus is one operator which will perform addition of two numbers. And what about this equal to? Equal to is also an operator. Equal to also one of the operators. So what equal to will do here, once a plus b is added, the result will be stored into this variable. So who is assigning the result into this variable? Equal to. So equal to is called assignment operator. Okay, so here plus also equal. So these are all called operators. And what is a and b initially before using this expression? A and B are just variables. Now once you use those variables inside the expression, we call them as operands. A, comma, B called as operand. So the variables which are participated inside this expression along with the operators, they are called operand. Okay, so operator means what? It is a symbol which will perform an operation, which will perform an, it can be any type of operation. Here plus is one of the examples. Plus will do the addition operation. Equal to will do the assignment operation. So whatever value we have here 10 will assign to the a. Who is doing that? Equal to is doing it. Same thing 20 is assigning into the b. So equal to is doing that which is also an operator. And here plus is an operator which will perform addition of these two numbers and storing the result into variable is again by equal to stored the result in the result variable. Okay, so operator means a symbol which will perform an operation. The variables which are participate inside this expression, we call them as operands. Before using here, just they are the variables, but once you started using the variables inside this expressions along with operators, we call it as an operand. Okay, now in Java, there are various types of operators are provided. So let me just list out here types of operators. So to perform any type of operation, we have to use different types of operators. Now what are the different types of operators provided by Java? There are n number of operators. Mainly we will use these six types of operators very commonly. So the first category, arithmetic operators. There are five operators comes under this category. One is plus, minus, star, slash, and percent. Okay, these are all called arithmetic operators. And relational or comparison operators, second category, relational or comparison operators, greater than, greater than or equal to, less than, less than or equal to, not equal to, double equal to. So these are all comes under relational or comparison and operators. Then logical operators, and or not, three operators which are comes under logical operators. And plus plus is called increment operator, minus minus is called decrement operator. I will show you demonstration how can we use these all operators. So plus plus is increment operator, minus minus is a decrement operator, and equal to is an assignment operator. We already discussed which will assign some data to the variable. So like this, we have some more assignment operators like plus equal to, minus equal to, star equal to, slash equal to, percent equal to. These are all assignment or we can also call as shorthand operators. And conditional or ternary operator, question mark colon, one operator. Question mark colon is one single operator which is conditional or ternary operator. So totally these are the six types of operators which we are going to discuss. So first thing, let us start with arithmetic operators. Let's go to Eclipse and go to our project. So let's create a new package for today. I can create by click on SRC, new package. I say day three, click on finish. So now we created a new package. So inside this, I'm going to create a new class.
01:28
Speaker A
doing here the plus is adding two numbers A and B right so which is basically called as an operator means an operator is a symbol which will perform an operation that's a simple definition operator is a symbol which will perform an operation there are multiple operators which we have
01:49
Speaker A
Whenever you start writing a new Java program, you must create a class. So how to create a class? You can simply provide the name. So here I'm giving some name operators demo and also I'm taking main method here. Select the checkbox and say finish now. So which is created a new class and this is the main method. So inside this block, we have to write our Java code. So inside this block, we have to write a Java code. Now the first thing, arithmetic operators. So how to use this arithmetic operators? So let us take two variables. So mainly arithmetic operators works on numbers or numeric type of data. So if we have integers or if you have a float or if you have a double. So if you have a numeric data, these operators will work. So arithmetic operators basically we use to perform arithmetic calculations. So what are the arithmetic calculations? Addition, subtraction, division, multiplication, modulo division. So these are all basic arithmetic operations. So to perform these operations, we have to use the symbols and we need a numeric type of data. Okay, so these operators works only on the numeric type of data means all integers, float, double, and so on. So let me take two integer variables here. I can take int a = 10, int b = 20, or I can directly say b equal to 20. So because a and b are both same data type, I can just specify only once in a.
02:11
Speaker A
into this variable so who is assigning the result into this variable equal to so equal to is called assignment operator okay so here plus also equal so these are all called operators and uh what is a and b initially before using this Expression A and B are just a variables now once you use those
02:37
Speaker A
10 b 20. So two variables I have created. Now I will apply these operators on these two values. So what I will do is I can directly write system out. println and simply I can say a + b. So when I say a plus b,
03:02
Speaker A
will perform an it can be any type of operation here plus is one one of the example plus will do the addition operation equal to will do the assignment operation so whatever value we have here 10 will assign to the a who is doing that equal to is doing it same thing 20 is assigning
03:18
Speaker A
plus will perform the arithmetic operations. When I say a plus b, it will perform addition of two numbers 10 + 20 which is 30. Now I want to write simple a meaningful message here. I can say sum of a and b is. So how to concatenate this? This is a string. Whatever we put in the double quotation, that will be printed as it is in the console window. And a plus b is expression which will perform addition operation. So how to concatenate these two? We can put this a plus b in the bracket and then concatenate. So here plus is acting as two different things. One is a concatenation, other one is addition. So when I use plus operator between two numbers, it will perform addition operation. When I use plus operator between two strings, it will perform the concatenation operation. Or if I use plus operator between a string and number, then also it will perform the concatenation operation. And if I look at here, this is a string and this will return the number after addition. It will return the number. So between this, I'm using plus operator means it will perform the concatenation. So when I execute this, this will print a meaningful message. So sum of a and b is 30. So like this, let us try to use other operators, other arithmetic operations. So here this is difference, so subtraction. How can we do this? So higher value is b, right? So I can say.
03:36
Speaker A
will perform an operation the variables which are participate inside this expression we call them as a operants before using here just they are the variables but once you started using the variables inside this Expressions along with operators we call it as a operant okay now in
03:57
Speaker A
Or else I can take a 20 and b 10. Okay, so here I can say a minus b, a minus b. So this is the expression a minu.
04:21
Speaker A
use these six types of operators very commonly so the first category arithmetic operators there are five operators comes under this Cate one is plus minus star slash and percent okay these are all called arithmetic operators and relational or comparison operators second category relational
04:46
Speaker A
or comparison operators greater than greater than or equal to less than less than or equal to not equal to double equal to so these are all comes under relational or comparison and operators then logical operators end or not three operators which are comes under logical operators
05:11
Speaker A
and plus plus is called increment operator minus minus is called decrement operator I will show you demonstration how can we use these all operators so Plus+ is increment operator minus minus is a decrement operator and equal to is an assignment operator we already discussed which will assign
05:31
Speaker A
some data to the variable so like this we have some more assignment operators like plus equal to minus equal to Star equal to slash equal to percent equal to these are all assignment or we can also call as short hand operators and conditional or ternary operator question mark
05:51
Speaker A
colum one operator question mark column is one single operator which is conditional or ternary operator so to toally these are the six type of operators which we are going to discuss so first thing let us start with arithmetic operators uh let's go to eclipse and uh go to our project so
06:14
Speaker A
let's create a new package for today I can create by click on SRC new package I say day three click on finish so now we created a new package so inside this I'm going to create a new class
06:31
Speaker A
whenever you start writing a new Java program you must create a class so how to create a class you can simply provide the name so here I'm giving some name operators demo and also I'm taking main method here select the checkbox and say finish now so which is created a new class and
06:53
Speaker A
this is the main method so inside this block we have to write our Java code so inside this block we have to write a Java code now the first thing arithmetic operators so how to use this arithmetic operators so let us take two variables so mainly arithmetic operators works on numbers or numeric
07:19
Speaker A
type of data so if we have integers or if you have a Flo or if you have a double so if you have a numeric data these operators will work so arithmetic operators basically we use to perform arithmetic calculations so what are the arithmetic calculations addition subtraction
07:38
Speaker A
division multiplication modulo division so these are all basic arithmetic operations so to perform these operations we have to use the symbols and we need a numeric type of data okay so these operators Works only on the numeric type of data means all integers float double and so on so let
07:59
Speaker A
me take take two integer variables here I can take int a = to 10 int Bal to or I can directly say b equal to 20 so because A and B are both are same data type I can just specify only once in a
08:14
Speaker A
10 B20 so two variables I have created now I will apply these operators on these two values so what I will do is I can directly write system out. PRN and simply I can say A+ B so when I say A plus b
08:33
Speaker A
plus will perform the arithmetic operations when I say A plus b it will perform addition of two numbers 10 + 20 which is 30 now I want to write simple a meaningful message here I can say sum of A and B is so how to concatenate this this is a string whatever we put in the double quotation
08:55
Speaker A
that will be printed as it is in the console window and a plus b is expression which will perform addition operation so how to concatenate these two we can put this a plus b in the bracket and then concatenate so here plus is acting as a two different things one is a concatenation other
09:14
Speaker A
one is addition so when I use plus operator between two numbers it will perform addition operation when I use plus operator between two strings it will perform the concatenation operation or if I plus if I use operate between a string and number then also it will perform
09:33
Speaker A
the concatenation operation and if I look at here this is a string and this will return the number after addition it will return return the number so between this I'm using plus operator means it will perform the concatenation so when I execute this this will print a meaningful message so sum
09:51
Speaker A
of A and B is 30 so like this let us try to use other operators other arithmetic operations so here this is difference so substraction how can we do this so higher Valu is B right so I can say
10:10
Speaker A
or else I can take a20 and B10 okay so here I can say a minus B A minus B so this is the expression a minus B is the expression this will perform subtraction and the result will be concatenated
10:26
Speaker A
with the string so difference of a and t is a minus B and then multiplication so multiplication so multiplication of A and B is a star B Star is representing multiplication so whenever you want to multiply you can use star symbol and again plus is for just concatenation now
10:50
Speaker A
division in division of A and B is a I can say A/B slash is a division operator and there is one more operator which we have modular division modular division means what percent a percent B is a modular division so here we need to understand what is the difference between Division and
11:17
Speaker A
modular division slash and percentage so slash operator will return the coent value after uh division for example say 5 / 2 5 perc 2 so here I'm using two different operators so it will perform the division like 2 two's are four and one is a remainder right so when I use slash
11:46
Speaker A
operator this will return the quent value which is two when I use percent operator this will return the remainder value so this is one okay so both are division operators but the slash will return return the coent value whereas percent will return the remainder value okay Division and
12:12
Speaker A
modul and again we already know multiplication substraction and then addition so these are the basic arithmetic operators now let us try to execute run as Java application so now we can see the result here so this is we can get all the results so here I am not storing the result
12:33
Speaker A
in any other variables I'm just directly uh doing the arithmetic operations and then I'm directly keeping inside the print statement suppose if you want to store the result in some variable okay then what you can do for example here I'm taking one more variable called inter result equal to
12:54
Speaker A
A+ B and then you can use this variable directly here instead of printing a plus B you can directly print result so here you can just concatenation result so this is another way suppose if you want to store a result in some particular variable you take another variable so what you can do
13:17
Speaker A
is you can store a plus b value in the result variable and what is the type of this variable again integer because a plus b will return the number which is integer so result also should be integer type and once you hold that result in a variable then you can print this variable
13:34
Speaker A
so this is also another way and if you don't want to use any other variable then you can directly put this expression inside the printer instead of writing result you can just directly say A+ B so this is also fun you can put the result in another variable and print that variable or you
13:53
Speaker A
can directly write an expression inside the print statement you will get the same output okay so this is all about arithmetic operators addition subtraction multiplication division and modular Division and now we have another type of operator relational or comparison operators and
14:16
Speaker A
these operators especially we use to compare the values and most important especially when you're working with the conditional statement looping statements we frequently use these operators so relational and comparison operators so let us see how to use this relational or comparison operators
14:37
Speaker A
next relational or comparison operators so greater than greater than or equal to less than less than or equal to this is not equal to and double equal so these are all comes under relational compassion operators now here all relational or comparison operat ators will return a Boolean value remember
15:04
Speaker A
this always returns a Boolean value Boolean value means what yesterday we discussed what is Boolean value what is Boolean value Boolean means what yes either true or false it can be true or it can be false which is called as Boolean value so when I use relational operator or comparison operator
15:30
Speaker A
that will return either true or false okay for example here I'm simply saying system. p a greater than b so greater than is what relational or comparison operator so what this greater than will do the greater than will compare a with B now what is the value of a here 20 what is the
15:54
Speaker A
value of B 10 20 greater than 10 true or false 20 greater than 10 true or false true right true so this expression will just print true that means the greater than symbol compare the two values and it can return either true or false okay suppose I'm writing the same statement like this a less
16:23
Speaker A
than b less than a less than b a value is 20 B value is a 10 so 20 less than 10 is it true or false it is false because 20 less than 10 which is false so this expression will return return
16:42
Speaker A
false okay let's try so all relational operators or comparison operators will return true or false basically they will return the Boolean values true or false okay and similarly we can also use other operators let's say system. out. and here I say a dater than or equal to B now tell me what is this
17:10
Speaker A
expression will WR a greater than or equal to B so actually there are two comparisons here one is greater than one is equal to what does it mean so when this expression will returns true in two cases one is a should be greater than b in that case it will return true another case is what a
17:36
Speaker A
should be equal to B if a and b values are equal then also it will returns true that's the reason greater than or equal to two comparisons a should be either greater than b or a should be equal to
17:53
Speaker A
B so one of the condition should be satisfied so then only it will returns true now according to our values a is 20 b is 10 20 greater than or equal to 10 true or false true or false 20 greater
18:09
Speaker A
than or equal to 10 true or false true why because greater than condition is true greater than is satisfied right 20 greater than b even though they are not equal still a is greater than b true right similarly here I will write like this a less than or equal to B true or false a less than b
18:35
Speaker A
less than false right because a is 20 b is uh 10 so 10 uh 20 less than 10 is false so whenever it become false then it will check another condition equal to a equal to b or not no a also not equal
18:52
Speaker A
to B so obviously it will return return false this will return false so two conditions are two comparisons are inclusive here so you can say this is the true and this is a false so now what I will do is I will make B value also 20 so initially B value is what 10 now I'm making as a
19:17
Speaker A
20 should I Define the data Ty should I specify the data type here is it really need data type here should I Define data type not needed right why because B is already created with the integer type here we already specified b as an integer type so next time when you're referring the b
19:39
Speaker A
or next time when you are changing the value of the B you no need to specify the data type again because this is a duplicated it will give you an error is clearly saying duplicate local variable B so you no need to specify the data type just reuse the variable and just change the value
19:58
Speaker A
initial 10 now it becomes 20 now after changing this value I can simply say a greater than oral less than or equal to B and also I will write a greater than or equal to B now tell me what is
20:18
Speaker A
an output of these two expressions a less than or equal to b a greater than or equal to B what is an output of these two statements obviously true why they are true why because it will first check the
20:34
Speaker A
less than condition a less than b true or false false then it will check equality a equal B are true or false true so obviously it will return return true that means either less than or equal to one of them should satisfy now if you come to the second expression a greater than b a greater
20:55
Speaker A
than b false a is not greater than b but a equal to B true so it is finally written true okay so two comparisons are here if first one is not matching then it will go to the second one if
21:09
Speaker A
first one is not satisfying then compare with the second one okay so less than or equal to greater than or equal to now when I run this this two expressions will finally return true and true so all relational or comparison all relation or comparison operators are returning a Boolean
21:31
Speaker A
values that you have to notice here true or false nothing else only true or false is written right now we say not equal to equal to so for example let's say syst P I can say a not equal to not
21:50
Speaker A
equal to B what do this mean what is an output of this a not equal to B I'm I'm clear is saying a not equal to B true or false So currently A and B values are same but here what I'm expecting not
22:08
Speaker A
equal to B so obviously what happens this will return false because a not equal to B false why because A and B are not equal it's equal actually a value 20 b value 20 both are equal but here I'm
22:22
Speaker A
expecting not equal so it is obviously return false but if the same statement if you a same statement if you write like this a equal to b a equal to B now tell me what is a guys can you see
22:41
Speaker A
my screen the font is visible to everyone can you please confirm otherwise I'll just try to increase some okay let me try to increase little bit okay it's too much larger okay now I think it is fine okay so now you can see a equal to B now a value is a 10 sorry a value is a 20 and B
23:09
Speaker A
value is also 20 a value 20 b value is also 20 now what is an output of this expression a equal to B obviously it is true because the values are same I'm expecting double equal so when I run this this
23:23
Speaker A
will give you false and true okay so if I notice here all relational or comparison operators will returns a Boolean value that means a true or false okay suppose I want to store the result in some variable I want to store some variable in a variable for example here I say a greater than b
23:51
Speaker A
this is my expression and I want to store result in a variable let's say result because result variable we already defined as an integer here but here I'm taking Rees now tell me what is the type of this variable so a greater than b will return either true or false a boing value will be return
24:12
Speaker A
returned now when I store that value in a variable what is the type of this variable obviously what type of variable it should be we storing a Boolean value into the variable remember this we are not storing number we are not storing integer but in the previous example A plus b will return
24:35
Speaker A
the integer 20 plus 10 return the integer so this variable should be integer but here a greater than b will return the Boolean value so this variable should be what Boolean type of variable okay and after that you can just print result so like this you can directly put Expressions inside the print
25:00
Speaker A
statements or else you can store the result in another variable and then you can print that variable so either way you can do it okay so this is rning false a greater than b is false because we already changed the value here okay so this is all about relational or comparison operators so
25:24
Speaker A
what these operators will do these operators will compare two values it will compare two values and returns a Boolean value either true or false now similarly we also have something called uh logical operators the next category very important listen carefully because in the next
25:54
Speaker A
topic conditional statements looping statement when I discussing those topics these operators are very useful so logical operators and or not so these three are called logical operators and logical operators also always returns a Boolean value returns Boolean value so Boolean value means
26:22
Speaker A
again true or false so logical operators also so always returns a Boolean value true or false but what is the difference between relational and logical operators so relational operators we can use only between two variables if I look at here these operators will work between two
26:48
Speaker A
variables A and B and these two variables can be any data type it can be numeric it can be string it can be character whatever it is so these relational operators we can use in all kinds of data types but logical operators we can use only Boolean data types we can use only Boolean
27:12
Speaker A
data types that means we need a Boolean variables between these Boolean variables we can use logical operators so before discussing this end or not so let me just give you a simple table so that you can easily understand when these operators will return return true when these operators
27:31
Speaker A
return false so as I said The Logical operators Works between two Boolean variables this is a fundamental Point Works between two Boolean values or variables anything okay so how it will work let me show you simple I'll take a small table in Excel sheet so let us try
27:55
Speaker A
to understand how exactly The Logical operator works let me unra the okay so here I'm taking uh some variable called X and Y X and Y logical operator X and Y X r y not X not y okay and or
28:23
Speaker A
not so this is both are same actually we just remember this and here I'm taking different combinations so and or not so these three operators Works between two buan variables so X and Y are the Boolean variables okay now here I'm taking four different combinations just
28:43
Speaker A
OB okay so now x value let us assume it is a true y value is also true x value true y value is false x value false false and Y value true now x value false and Y value also false y value also false
29:11
Speaker A
let us take a different combinations of data so X and Y are the Boolean variables Boolean variables means what which contains only Boolean values either true or false now end operator so as I said end or not so these operators also will return a Boolean value true or false but when the
29:29
Speaker A
end operator will return true X and Y I'm using this operator between two variables X and Y are what Boolean variables here also Boolean variable here also X is a Boolean variable so The Logical operators Works between a Boolean values or Boolean variables now if you look at here end
29:50
Speaker A
operator will return true only if X and Y are true okay so here X and Y are true so X and Y will return return true so both are true here x should be true y also should be true then only
30:06
Speaker A
end operator will returns true in all other cases it will return false in all other cases it will return false that is a behavior of end operator so only one case it will returns true and rest of the cases it will return false so and end means what X and Y both should be true
30:33
Speaker A
then only it will returns true even one of them is false it will return false in the second case Y is false third case X is false in the last case both are false so it will return False only in one
30:47
Speaker A
case it will return returns true when it will return true if both values are true then only end operator will returns true now come to the r r R means either X or Y at least one should be true then it will returns true for example in the first case both are true so obviously it
31:07
Speaker A
will return returns true in the second case X is true even though Y is false fine X is true so it will also returns true in the third case Y is true so it will returns true only in the last
31:21
Speaker A
case both are false so here it will return false so in three different cases it will returns true only in one case it will return false so how exactly this R operator Works r r means either X or Y one should be true at least one should be true then only it will returns true in all
31:42
Speaker A
three cases either X or Y one of it is true so it returns true only in the one case both are false so it is rning false that is our operator now not not means negation opposite so x value
32:01
Speaker A
is a true obviously not x value should be false and x value is false obviously not x value will be true negation okay and or not so these three are called logical operators and uh these logical operators we can use between two Boolean values two Boolean values that is the major difference
32:28
Speaker A
between relational and logical operators both are comparison so relational operators also we can use it for comparison logical operators also we can use it for comparison but the difference is relational operators we will use for any type of data but logical operators we will use
32:46
Speaker A
only Boolean type of data now this is a simple table you can easily understand so notx is an opposite for example X Valu is are true not x value should become false suppose x value is equal to false then not x value becomes true like this so the opposite of X for example let's
33:08
Speaker A
say I'm taking one more let say not y okay not y now you can just tell me I'm taking not y so here y value is equal to here y value true and what could be the not y value if the Y value is
33:25
Speaker A
equal to true not y becomes false opposite so if the Y value is equal to false here y value is equal to false then not Y is equal to True opposite okay only one single operator not not means negation okay so simply remember this table you can easily understand so I'll keep this table
33:49
Speaker A
here so these are the logical oper okay now so let us see practical example how can we use this logical operators now go to eclipse and uh so logical operators only three operators end or not and logical operators always returns either true or false and it works between two two Boolean values
34:29
Speaker A
two Boolean values now I'm taking simple example I will Define two variables which are Boolean type of variables let me take Boolean X I'll make it as a true Boolean y I'll make it as a false Boolean x equal to True y equal to false because logical operators Works between two Boolean variables X is
34:55
Speaker A
Boolean variable the value of x is true the value of y is false now you tell me the output for this system out. print I can say X and Y now what is an output of this statement X and Y end operator
35:10
Speaker A
I'm using true or false obviously it is false why it is false because end operator will return true only if both are true but here only X is true Y is false so it will return false now instead of
35:29
Speaker A
end I'm trying to use R operator R now what is the return Type R means double pipe you can see pipe symbol on your keyboard you have to type two times and what is output of this statement true or
35:45
Speaker A
false this is true why because XR R means either at least one should be true either X or Y even one it is true that is final result is true so in this x value is a true so the result is true now
36:02
Speaker A
you can say not x what is an output of not X and what is an output of not y not X and not y x value is a true so not x value should be obviously false and Y value is a false so not y value is obviously
36:21
Speaker A
true right so this is how we can simply use logical operators between two Boolean variables now we can see here the last four values false true false true okay now I'm going to show you some more examples on Boolean data types now just observe you guys can tell me the output here I'm
36:45
Speaker A
creating one Boolean variable let's say Boolean B1 equal to 10 greater than 20 is the statement correct or not can we write statement like this Boolean B1 equal to 10 greater than 20 valid or not this statement is valid or not please respond is the statement valid or not Boolean B1 equal to
37:09
Speaker A
10 greater than 20 is the statement valid or not yes it is valid statement why because 10 greater than 20 will return true or false because we are using relational operator so greater than we'll compare the two values and return the Boolean value so 10 greater than 20 will return return
37:30
Speaker A
true or false that I'm going to store in another Boolean variable so this expression is valid okay now here I'm just trying to print B1 so what is an output you will get here true or false false right because 10 is not greater than 20 so 10 greater than 20 is false so B1 value obviously
37:56
Speaker A
false now I'm taking one more variable Boolean B2 and here I say 20 greater than 10 20 greater than 10 now after that I'm trying to print B2 now what is an output of this true or false this is true
38:14
Speaker A
because 20 greater than 10 which is true and will be stored in B2 now I can say B2 this is returning true okay now you tell me this output system. B B1 and B2 are Boolean variables or not yes they are
38:31
Speaker A
Boolean variables right B1 is a Boolean variable B2 is also Boolean variable now can I use logical operators between this B1 and B2 yes we can use now I can say B1 and B2 what is an output of this
38:50
Speaker A
what is B1 B1 contains what a Boolean value false it is rning right and what is does B2 contains B2 is also a Boolean variable which is having true so B1 is false B2 is true now what is the output
39:07
Speaker A
of this end operator will return false because only one value is true the second one is false so obviously it return return false and now if I say B1 R B2 then it will return return true because we are using R of operator so R operator will return true if at least one value is true so
39:33
Speaker A
B1 B2 in B1 and B2 B2 is true so obviously it will return return true so we can also use this logical operators between two Boolean values and these Boolean values variables can get the output from different type of Expressions okay now I'm going to write one simple expression first of all let's
39:55
Speaker A
run this so the last two false and true we are expecting so this is false and true okay now you guys can tell me whether this is valid or not so in the first expression I can say 10 less than 20
40:16
Speaker A
and in the second expression I'll say 20 greater than 10 now tell me what is an output first of all tell me it is valid or not the statement is valid or not can we write the statement like
40:30
Speaker A
this so can we write the statement like this first of all I haven't used any variables in this I haven't used any Boolean variables I've directly written the expression if I look at this this particular expression will return true or false 10 less than 20 true and
40:55
Speaker A
this will return true or false 20 greater than 10 true so this is true and this is also true so I'm using end operator between two Boolean values so this is true this is also true true and true means the output is obviously true so you can write expressions in different ways by
41:17
Speaker A
using relational and logical operator so this is a combination of relational and logical operators okay so we can also combine relational and logical operators according to our requirement so now you understood relational operators and logical operators how to use
41:36
Speaker A
relational operators and how to use logical operators the major difference is relational or comparison operators we can use with any data types but logical operators we can use only with the Boolean data types okay now so let us move on to the next one increment and decre
41:56
Speaker A
ment operators so these are most important Java specific operators so before going to them so are you guys clear so far these three operators arithmetic relational and logical operators everyone please confirm in the chart in the chart window arithmetic relational logical
42:14
Speaker A
operators okay so now let us move on to the next one so these three are special type of operators so mostly everybody everybody is aware of these operators but these are little different type of operators yes you can also use relational operators with a string data type yes you can use
42:36
Speaker A
so that though in that case these operators will compare the alphabets so every alphabet is having some asky value internally so for example if I take a the asky value of a is 76 or 77 so like this for every character in your keyboard there is a asky character internally it will maintain
42:57
Speaker A
so when you compare when I use these operators relational operators between the strings basically it will internally compare the asking characters and accordingly it will return return true or false okay fine so now let us try to understand uh another type of operators so any anyway I'm going
43:22
Speaker A
to share this one right all the class demos so I think I no need to copy this programs in the notepad I think because I'm directly sharing these files yesterday also I have already shared these files I think you guys have noticed this so I think I this is not needed copy the entire
43:40
Speaker A
programing the notepad is unnecessary inrease the content not needed okay because these programs anyway I'm sharing them so differently and as a different files you will get open the files and you can see the right so now let us move on to the next one increment and decrement operators
44:00
Speaker A
most important listen very carefully increment Plus+ is called increment operator minus minus is called decrement operator okay guys so this is not a final notes guys okay I will also share some of the documents PPS and so on so once you finish the Java sessions and at the end of the
44:20
Speaker A
Java sessions I will give you one PP presentation and study material so which contains everything all the noes whatever we discussing during the session everything will be part of that noes ppds but not now after completion of java sessions so that you can see every Concept in that nodes and
44:37
Speaker A
document so that will be very very useful so don't think this is the final one okay so now let us see how to use increment and decrement of so Plus+ is called increment operator minus minus is called decrement operator plus plus is called increment operator minus minus is called decrement
44:58
Speaker A
operator first let us discuss about plus plus increment operator how to use increment operator and let us create new class I will name it as increment operator taking main method so in this just observe how can we use increment operator first so here uh Plus+ is basically called as
45:29
Speaker A
increment operator Plus+ is called increment operator okay suppose I'm taking one variable here in a = to 10 a is an integer variable which is having 10 now if I print a value simply I can say a in the print statement I can print a so obviously this will print the value of a which is
45:53
Speaker A
10 perfect now after printing this a value I want to increase the a value by one I want to increase the a value by one so normally how we will write an expression if I want to increase a value by
46:09
Speaker A
One initial values at 10 now I want to add plus one so normally how we can create without using increment or nothing just normal expression a = to a + 1 this is a normal expression no I'm I'm
46:29
Speaker A
I'm not asking to assign the data if you say a equal to 11 this is also correct but what you are doing here is the old value is replacing with the new value 10 is already gone now a becomes 11
46:43
Speaker A
I'm not asking to assign the new value I'm asking to increase the existing value that means a + 1 when I say A + 1 what will happen what is the current value of a 10 10 10 + 1 is
46:57
Speaker A
what 11 that 11 will be assigned to the a again previously a value is 10 now a value becomes 11 so when you print this a value one more time this time it will give you 11 right this is how we can
47:12
Speaker A
increment value by one we can simply say a = to a + 1 so a current value of a is 10 10 + 1 11 11 is a new value that again reassigning to the same variable whatever variable we are using
47:27
Speaker A
here after adding one we are reassigning the result into the same variable so initially a values a 10 after adding by one it becomes 11 so this is a normal way we can increment a value for a variable instead of writing this variable two times you can say a equal to a + 1 right you can
47:49
Speaker A
simply write one single statement which is A++ so I can simply say a a ++ I can say A++ that's this is exactly equal to a equal to a + one I commented the statement A++ is exactly equal
48:07
Speaker A
to AAL to A+ 1 so whenever you want to increase value by one you can simply use Plus+ operator so when I execute this this time also you will get the same thing now we can say 11 so A++ means
48:22
Speaker A
it is incremented a value by one so when print a value after A++ you will get 11 so this is exactly equal to a equal to A+ 1 this is a shortcut in Java it is supported increment operators instead
48:39
Speaker A
of writing the entire expression we can simply write A++ okay Plus+ is an increment operator which we can use to increment the value by one now in increment operator we have two different aspects one is pre-increment other one is post increment pre-increment and post increment just
49:06
Speaker A
observe this so this is one case this is one example case can call it as let a case one instead of AAL to a + 1 I'm directly using A++ so which is also incremented value by one and
49:22
Speaker A
is got printed now let me show you another case let's comment this just observe this in interal perspective these are most important just observe this case two here again I'm taking same variable in a = to 10 into a = 10 A++ so A++ this will increase a value by one right a value becomes 11
49:53
Speaker A
now I will store that result in another variable let's take one more variable like this so a = to 10 a ++ will become 11 and that I'm storing into result after that I'm printing the result value is this clear or not is it valid or not can we do like this A++ will increment the a value by
50:19
Speaker A
one right 11 it becomes 11 that I'm going to store in a variable and that I'm going to to print so what is the value are expecting here what is an output of the statement what is the output of the statement 11 right so when I run this code just see it is still 10 it is still
50:43
Speaker A
10 why is it so what happened here so when incrementing this value A++ it should become 11 right so the 11 should be assigned to the result and it should get 11 here but instead of 11 still we are getting 10 only but when I use this A++ in the previous case here we are
51:03
Speaker A
getting the incremented value so here we got a 10 and after incrementation we got 11 but what is the difference you have noticed here previous case and current case in the previous case after incrementation we are directly printing the a value but in this case after incrementation we
51:22
Speaker A
are storing the incremented value in the variable and then we are PR the variable that's only one difference you can notice but still it should print 11 but why it is printing 10 so normally what happens is even though it is got printed 10 whether it is incremented or not first of
51:43
Speaker A
all if you look at the result it seems it is not incremented right but it is incremented a values got incremented even though we are not getting here still it is incremented but why we are not getting the incremented value so there is a reason for that so whenever you are storing the
52:05
Speaker A
incremented value in a variable what exactly happening here is what is the current value of a 10 right so the 10 will assign to the result first after assignment incrementation will happen so after assignment incrementation will happen okay so assignment is happened so
52:28
Speaker A
result value becomes what 10 after assignment then incrementation is happened so the result value still it is 10 only why because a Valu is directly assigned to the result after assignment then incrementation is happen how we will know incrementation is happen or not you can directly
52:48
Speaker A
print a value then you will know exactly whether incrementation is happened or not right so if I print a value obviously you will get 11 you will get 11 incremented right by seeing the statement we understood a Val is incremented but why it is not printed here because the way
53:09
Speaker A
of execution is totally different so how it is got executing this expression when I store this value in a variable first a value directly assigned to the variable after assignment then incrementation is happened so after assignment if I print result still we are getting 10 here
53:27
Speaker A
and if you print a value here we are getting 11 so this type of expression is called post increment post increment post increment means what first assignment will happen then incrementation is happened post increment so first assignment is happened then incrementation is happened
53:48
Speaker A
that is the reason still we are getting result value is 10 so is this clear everyone so why we are getting the same value again after incrementation okay so this is called post incrementation this is called post increment operator or post incrementation post increment
54:11
Speaker A
operator okay now let me show you another case I hope this case is very clear to everyone so when I say A++ what is happening first a value is directly assigned to the result and after that it is incrementing so result value Still Remains 10 only right so now let
54:31
Speaker A
me show you the same expression let us see case three okay let me comment this right so case three now just observe this in the case three again I'm taking the same variable instead of A++ I will do Plus+ a I'm just keeping those Plus+ before
54:57
Speaker A
the variable so result equal to Plus+ a result equal to Plus+ a now just try to remove this now what is an output of this results what is an output you are expecting here 10 or 11 so instead of A++ I have written Plus+ a so plus plus a is called pre increment of operator
55:26
Speaker A
so this is called pre-increment pre-increment when I use Plus+ operator after the variable which is called post increment when I use Plus+ operator before the variable we can call it as a pre-increment so this time when you run this code you will get a result 11 so even though if
55:47
Speaker A
you print a value of a directly you can just see the value still till 11 so for both we are getting the 11 so how it is getting 11 here how the expression is executing so what is the
56:06
Speaker A
difference between po increment and pre-increment both are incrementation operators but what is the major difference in the pre-increment what is happening first it will increment that value after that assignment will happen in the post increment first assignment will happen
56:26
Speaker A
after that incrementation will happen but in the pre-increment first incrementation will happen after that assignment will happen so accordingly if I look at here first plus plus a means it is already incremented becomes 11 now 11 is assigned to the result so when I print the result we got
56:46
Speaker A
the 11 and again a is already incremented so when I print a value also we will get the same result okay so this is a major difference between post increment and then pre-increment both are increment operators in both the cases when I say A++ or Plus+ a both the cases the value
57:08
Speaker A
will be incremented by one but when you store the result in another variable there is a difference in the pre-increment and post increment okay so in the pre-increment what in the post increment first the variable value will directly assign to the variable then increment mentation will happen
57:26
Speaker A
in the pre-increment first incrementation will happen and after that assignment will happen so that's the reason we are getting the right value here but here first the value directly assign to the variable we are getting result value still 10 so everyone is understood this please confirm in
57:43
Speaker A
the chart window increment operator post increment pre-increment po increment pre-increment operators okay now the same thing is applicable for decrement operator also minus minus if you want to decrease the value by one then we use decrement operator so plus plus
58:10
Speaker A
is for incrementing value by one minus minus is for decrementing the value by one okay let's see one more example for decrement operator let me close this so let's create a new class I'll name it as decrement operator take main method as
58:38
Speaker A
a finish so same cases again we will see the first case it's normal let me take variable in AAL to 10 okay so normally if you want to decrease the value by one so what you will do a = to a minus 1 this is a normal expression so system. print if I print a value what is
59:02
Speaker A
an output of the statement a = to a minus one so current value of a is what 10 10 - 1 9 so 9 again reassign to the a now the current value of a is what nine so this is a normal expression
59:16
Speaker A
we got a nine same thing we can write by using minus minus you can say a minus minus so this is exactly the same as AAL to a - one so when you run this this will give you same value n
59:31
Speaker A
so this is normal case now we will see decrement pre- decrement and post decrement so we are not increasing the value here we are trying to decrease the value okay A minus minus means it will decrease the value by one so it becomes nine initially a value 10 now it becomes nine so
59:50
Speaker A
this is a normal way we can do now let's see the pre pred decrement and post decrement or post decrement and pre- decrement just observe this same a equal to into a equal to let's make 100 okay now I can say a minus minus and that I can store in a result a minus minus the result
60:18
Speaker A
I will store in a result variable and then I'm printing the result value here and after that I'm trying to print a value also now tell me the output of the first statement and second statement 100 or 99 which one you will get here when I print result you will still get 100 here
60:40
Speaker A
99 so how because it is a post decrement post decrement means what what is the post decrement post decrement was first the value will assign to the variable aable and then decrement will happen so what is the current value of a 100 so 100 will assign to the result so here we
61:02
Speaker A
got 100 after assigning then decrement is happen now a becomes 99 so when I print a value you will get a 99 so same formula it is also applicable here so this is post decrement first assignment happen then decrement happen so 190 and now we'll see the pre- decrement another
61:26
Speaker A
case so just commenting this now case three same thing but instead of a minus minus I can say minus minus ausus pred decrement now tell me the output of this first statement and second statement so now first statement obviously 19 second one is also
61:53
Speaker A
19 because first it will decrement happens and once it decremented then assignment will happen this is called pre decrement pre decrement and here this is post decr okay so now we got both 99 so this is called increment and decrement operators plus
62:23
Speaker A
plus minus minus again in the Plus+ we have a post decrement and pre- decrement in minus minus sorry po post increment and pre-increment in minus minus we have a post decrement and pre- decrement okay so clear everyone increment and decrement
62:43
Speaker A
operators now so let us see assignment operator so far by using increment and decrement operators we are able to increase value only by one or we are able to decrease the value only by one right but sometimes if you want to increase value more than one
63:05
Speaker A
or if you want to decrease the value more than one then how can we ACH this so plus plus will perform addition right plus plus will increment the value by one minus minus will decrement the value by one only one but I want to decrease I want to increase the value by
63:21
Speaker A
five or I want to increase the value by 10 similarly want to decrease a value by five I want to decrease a value by 10 so how it is possible so we can use shorthand operators so these operators we can use so these are the operators we can use so let me show you how
63:39
Speaker A
can we use these operators okay we can call it as assignment operators so let me create a new class yes because these are arithmetic related operations right because plus minus subtractions these are all related to numbers so only arithmetic operators we can
63:58
Speaker A
do it so how can we increase the characters how can we increase the characters and string it doesn't make any sense right so only for numbers these operators will work okay so now we'll see assignment operators equal is the first most assignment operator that we will
64:19
Speaker A
assign the value to the variable and other than equal to we also have some more types of operator we also call them as a shorthand operators okay let me show you something here so what are the assignment operators which we have these are all assignment
64:36
Speaker A
operators these are all assignment operators equal to plus equal to minus equal to Star equal to/ equal to modu divion equal to it's very simple I'll tell you so I can say in AAL to 10 I want to increase a value by one so normally how we will write right a = to a + 1 or A++
64:58
Speaker A
but this time I want to increase a value by five a value I want increase by five so normally how we will write an expression a = to a + 5 right so after that if you print a value then you will
65:13
Speaker A
get a 15 because initial value of a is 10 now here we adding 5 a + 5 10 + 5 15 again reassign to the a now we got a 15 here so here what we are doing basically we are increasing a value
65:28
Speaker A
more than one if it is a one we can directly use increment operator plus plus but here if you want to increase more than one you can write expression like this or in short way we can write A+ = to 5 this is called shorthand assignment operator a plus equal to 5 you don't
65:50
Speaker A
need to write variables multiple times simply can say A Plus equal to 5 plus equal to so this operator will increase a value by five so this will also gives you the same result 15 okay so this is a way we can increase value more than one okay suppose uh I want to decrease the value by
66:17
Speaker A
one so this is for incrementation now I want to decrease the a value by five decrease then how can we write an expression a = to A Min - 5 a = to a minus 5 so a value current value
66:30
Speaker A
of a is 10 10 - 5 five so the current value of a becomes five so when I execute this you will get a five because we decrease a value by five same expression you can write like this you can say a
66:47
Speaker A
minus equal to 5 so not only five you can use any number A minus equal to 5 this is another short hand assignment operator a minus equal to 5 so this will reduce the value by one so now
67:00
Speaker A
we will get a five same expression you can write like this a = A+ 5 you can directly shortcut you can write a plus a plus equal 5 or you can write a minus = okay so this is a plus equal to and
67:17
Speaker A
also minus equal to so star equal to SL equal to modular division so how can we use this operators so just observe this so this is one example let's comment this first and at the time of practicing you can just remove
67:40
Speaker A
the comments and do practice okay now say example two so when I say in a = to 10 now I want to multiply this a okay let's say uh a equal to a star two a equal to a into two
68:00
Speaker A
so when I print a value what is an output of this statement what's an output of this statement a star two 20 right so because current value of a is 10 10 into 20 10 into 2 20 20 will
68:16
Speaker A
again reassign to the a now here we will get a 20 as an output so this is our expected normal expression AAL to a star okay so instead of writing two variables you can simply in shortcut you can write like this a star equal to two a star equal to two so a is multiplying with
68:38
Speaker A
the two and again reassign the new value into the same variable so this is another shortcut rate a star equal to two now we got a 20 so this is exactly the same as this one similarly slash equal to modular division equal to same thing so let's say example okay so I can say in a = to 10
69:06
Speaker A
and now I can say if you divide this a by two how can we divide a = to a/ 2 this is how we can do right a equal to a/2 a value 10 10 by 2 5 so what is an output you are getting
69:20
Speaker A
here by print a value what is an output of this so here 10 a value 10 10 divided two what is an output slash slash operator will return the coent value which is five so this is division operator
69:39
Speaker A
and instead of writing AAL to a/2 in shortcut we can simply write a slal to 2 short hand operator this will also gives the same result P okay same thing you can apply for modular division also so this is example four so instead of Slash you can simply say modular division so normally
70:11
Speaker A
how we will write a equal to a percent 2 so this will do the division and remainer will store into the a so here also it will do the same thing so when you print a value what is an output you will
70:21
Speaker A
get here this is mod division Operator 2 5 are 10 remainder is zero so zero is a r Vector so these are all shortcut operators you can also write expression like this nothing wrong in Java okay but if you look at these type of Expressions somewhere you should not be confused okay you
70:44
Speaker A
should understand that expression so that's why I'm saying all these things nothing wrong you can use normal expression also if you're not familiar with this it will work okay the these are Java specific related operators these are all comes under assignment operators so here
71:00
Speaker A
equal to is a assignment operator it will basically assign the value into the another variable and uh I forgot to tell you one more operator guys in the relational operators uh we also have a double equal to right so here we have seen double equal to means it will compare
71:22
Speaker A
the two values if both are equal returns to both are not equal return false so now you guys can tell me what is the difference between double equal to and single equal to double equal to and single equal to what is the difference between double equal to operator and single equal to
71:45
Speaker A
operator dou equal to is a relational operator which will be used for comparing the two values and return returns true or false okay whereas equal to is a assignment operator which will assign the value into the variable which will assign the value into the variable so totally
72:15
Speaker A
different okay you should not use W equal to in every place so whenever you want to assign data use just single equal to whenever you want to compare something you just use double equal is this clear everyone difference between double equal to single equal to as per
72:33
Speaker A
Java so double equal to is a relational operator comparison operator it will compare the values and returns true or false whereas the single equal to will just assign the value into the variable so it is an assignment operator fine so now let us move on to the last one
72:55
Speaker A
conditional or ternary operator question mark and colon this is called conditional or ternary operator question mark and colum so how to use this question mark and colum so we need to know the syntax first and if you know the syntax you can easily use it so tary
73:17
Speaker A
operator or conditional operator we can also call so the syntax is first we specify the variable equal to expression question mark okay and here Result One Call and result two so this is a syntax actually so with this syntax we can use tary operator question mark colon so here the question
73:43
Speaker A
mark comes and here the colon comes so this is the expression actually the syntax let us see one example how to use this stary operator where to use take a new class and I name it as ternary operator so very easy just try to understand this so what is the syntax this is the syntax if you
74:13
Speaker A
know the syntax you can easily use it okay so now let me show you one example example one how to use tary operator here I'm taking two variables int a = 100 B = 200 int a = 100 b equal to 200
74:34
Speaker A
now I want to find which one is largest number I just want to print whichever largest or not a is largest or B is largest B is the largest number so that we need to find through program I don't want to directly print A and B if I print B value I have assumed I have I have decided 200
74:54
Speaker A
is a largest value no the program should decide according to the condition it will automatically checks which one is the largest number and it should print as an output largest number as an output okay basically we have to first compare these two whichever is the greatest number that
75:12
Speaker A
we have to print in the console window that's our requirement so by using this tary operator we can achieve this just observe very carefully here inter I'm taking one variable Collex just observe the syntax the same syntax I'm just replacing it so first thing is what variable
75:31
Speaker A
so here I'm taking one variable index equal to expression expression means what the comparison so here in the bracket I can say 100 okay or I can say a B I have taken so let's take a equal to 200 and b equal to 100 anything is fine so here I'm taking uh a greater than b this
75:55
Speaker A
is called expression this is called comparison so here we are comparing it so expression then question mark So result one result two is what result one I can say a comma result to I can say B and then semicolon so this is a complete tary operator expression and after writing this
76:18
Speaker A
you can just print the value of x then what will happen so how exactly it will work so let us try to understand this this is a expression right so a value 200 B value 100 so a is a 200 B value is
76:34
Speaker A
100 what this expression will return true or false a greater than b true or false true so if this expression returns true then the first a value will be assigned to the X okay if that Expressions returns true the a value will assign to the X if this expression is true
77:01
Speaker A
this a value will assign to the X then here we will get a a value so if I execute this just observe okay let me just run this so you can see we got a 200 how we got a 200 here so a
77:19
Speaker A
greater than b true or false true if it is a true a value is assigned to the X what is an a value 200 200 is assigned to the X now we got a 200 output okay suppose I change that expression
77:33
Speaker A
a less than b then what will happen expression true or false false if the expression is false then the B value assigned to the X and then here x will print B value which is 100 like this so how exactly this tary operator works if the expression is true then the a value will be
77:59
Speaker A
return if the expression is false then B value will be returned to the so this a value will store in X if the expression is false B value stored in the X so according to this if you want to find largest of two numbers how can we do it you can say a greater than b if a greater than
78:16
Speaker A
b a is the largest if a greater than b false then B is the largest so like this you can use tenary operator so let me show you one more example you guys can understand so when I execute this
78:31
Speaker A
this will return 100 because B is got return into X this is one example let me take another example so this time you guys can tell okay let me comment this now example two just observe how I writing the statement first tell me
78:58
Speaker A
it is valid or not in x equal to X is a variable okay in the expression I'm writing 1 equal to 1 question mark 100 coln 200 okay now I'm printing the value of x now tell me output of the X first
79:19
Speaker A
of all let me tell me this statement is valid or not is is the statement valid or not yes or no line number 20 the statement is valid or not yes obvious it is valid why because X is
79:36
Speaker A
a variable 1 equal to one is an expression this will return true or false so that expression is always written true or false here which one it will return 1 equal to one means true right so if it is a true 100 will assign to the X if the expression is false 200 will assign to the
79:55
Speaker A
X okay now what is an output of X here obviously 100 because condition is true expression is true so 100 is assigned to the X then we got an X so this expression is perfectly correct okay now let me write another type of expression in x equal to my expression is 1 = 2 question
80:22
Speaker A
mark okay question mark uh I can say 200 col 100 okay now tell me the value of x is what what is an x value 200 or 100 obviously it is 100 why because this expression returns false if the expression return false the 100 will assign to the X so the x value is 100 x
80:53
Speaker A
value is 100 perfect okay so guys now you understood how exactly this tary operator is working yes I will show you we can also use it for Strings also yes so first of all have you understood how exactly this tary operator is working first it will check
81:12
Speaker A
the expression if it is a true the first value assigned to the variable if it is a false the second value assigned to the variable that's how it will work okay so I will show you more examples you will understand this better so now my requirement is this is example two so example
81:29
Speaker A
three so here uh I will take one variable person age let's say 30 I want to check this person is eligible for o or not I want to check this person is eligible for o or not through ternary operator
81:48
Speaker A
I want to print eligible or not eligible simply based on the age so my condition is if the person age is greater than or equal to 18 he's eligible is less than 18 he's not eligible that's a condition so how can we achieve this using tary operator very simple first create
82:10
Speaker A
a variable called result and what would be the expression here when he is eligible for OT if the AG is greater than or equal to 18 eligible for so here I'm taking that variable person age person age okay greater than or equal to 18 this is the expression person age is the
82:30
Speaker A
variable I have already defined above so get this is a condition expression question mark if this expression is true if this expression is true what is an output I should get eligible so in the double quotations you can put because this is a string right eligible colon if the
82:52
Speaker A
expression is false then what we have to get not eligible semicolon okay so now if you print result result is a string variable now why because this will return eligible or not eligible this is a string value so I have to take this variable as a string now tell me what is an output of this
83:15
Speaker A
eligible or not eligible eligible why because I have taken person is 30 so person is greater than equal to 18 the expression is true if it is a true this part will store in the result if it is false not eligible will store so when I execute he is eligible suppose let us make this as
83:38
Speaker A
15 now the condition become false as soon as the condition become false then not eligible will assign to the result so when I execute this you will get not eligible okay so this is how we can use tary operator we can also achieve this by using conditional statement if else conditions so
84:05
Speaker A
in the next classes we will discuss that so this is called tary operator okay so with this we have completed all types of operators arithmetic operators relational or comparison operators logical operators increment and decrement again in increment decrement we have pre and post increment
84:26
Speaker A
and decrement assignment or shorthand operators and conditional or tenary operators so these are the operators most commonly used in Java okay so again all these operators again divided into three categories three categories okay so one category is called unary operators unary operators binary
84:56
Speaker A
operators tary operators okay ternary operators now what is this actually what is unary what is binary what is ternary unary operators means those operators we can use with single variable the unary operator means those operators we can use with the single variable now can you tell
85:26
Speaker A
me what are the operators here we can use with single variable can you just tell me what are the unary operators unary operators means the oper it can be any type of operator which comes under any category but those operators we can use with single variable just with single variable we can
85:46
Speaker A
use those operators so what are those operators we can see here just tell me in individually unary operators just tell me symbols so what are the operators unary means those operators we can use with a single variable remember this term Single variable see arithmetic operators if you want to
86:11
Speaker A
use at least two variables we required right so when you can perform addition at least two variables you requir when you perform subtraction when you can perform Division and modular division at least two variables we required right so they not comes under unary operators so unary means
86:28
Speaker A
only one we should able to apply that operator only on single variable so such type of operators we call it as a unary operators now tell me what are the unary operators Plus+ is a unary operator right just single variable we require minus minus is also unary operator because single variable
86:52
Speaker A
be required same thing plus equal to minus equal to okay star uh star equal to slash equal to and modular division equal so to use these operators we need only just one single variable is enough right or wrong single variable is enough or not to use these operators plus plus minus minus plus
87:17
Speaker A
minus plus star equal to SL equal to so to use these operators just one variable is required so these are all comes under unary operators okay even equal to also single equal to okay and not these operators we can use with single variable so we can call them as unary operators
87:45
Speaker A
now binary operators tell me what are the binary operators at least two variables we should have so if we want to use these operators at least two variables we should have so what are those operators what are those two variables you must have two variables if you want to use binary
88:04
Speaker A
operators all arithmetic operators we comes under binary operators because two variables at least we required similarly all relational operators also comes under binary because at least two values we require to compare right two values at least we need to compare so all relational
88:27
Speaker A
operators comes under binary operators next what next arithmetic operators B arithmetic operators relational operators what else logical operators these two comes under binary but not comes under binary not is comes under unary because only one single variable is required two variables
88:51
Speaker A
not required but if you want to use end or at least two variable two Boolean variables are required right so end or also comes under binary operator right so these are all comes under binary operators at least two variables we required to use these operators now finally we have only one
89:12
Speaker A
ternary operator three variables required at least three variables three uh variables required which is tary operator colum same in this three variables are required so three variables in the sense what if I look at this this is one this is two this is three okay three things are
89:34
Speaker A
required if I look at the expression this is one variable this is second this is thir if you have these three then only we can use tary operator right so tary means three binary means two unary means one so unary operators we can use with single variable by binary operators we can use
89:53
Speaker A
with two variables ternary operator we can use with three variables okay so these are all about operators concept so these are all fundamental very basic very fundamental concepts you have to practice a lot so if you're not practicing these things upcoming sessions or upcoming Concepts
90:17
Speaker A
you cannot understand the coming sessions we will discuss conditional statement looping statement so many things so many examples these are all fundamentals if you not understood this you cannot understand further Concepts so you have to practice this multiple times you need
90:32
Speaker A
to aware of this okay so clear everyone please confirm in the chat window once again operators concept right so let us stop here for today's session and do this practice and I will give one assignment based on this topic yesterday topic and today's topic yesterday we discussed about
90:57
Speaker A
variables and data types and today we discussed about operators now based on that I will give you one small assignment you guys can try this I will also provide the solution for this but this is a little different I will tell you what exactly it is swapping of two numbers very popular program
91:19
Speaker A
but I'm expecting to do this the different I'll tell you how can we do it swapping of two numbers what is swapping so what is swapping so let me just give you logic you guys can try so swapping
91:34
Speaker A
means the interchanging of values between two variables for example let's say initially I'll take a value 10 B value 20 so before swapping so before swapping the a value is a 10 B value is a 20 so after swapping okay after swapping I should get a value 20 b value 10 so these values should
92:03
Speaker A
be interchanged that is called swapping you have to achieve this okay so how can we achieve this so most of the people will use a temporary variable a simple logic they will use for example I have let's say three containers let us say this is a this is B and let us take C also C is a temporary
92:26
Speaker A
variable it doesn't have any value now initially a value 10 B value 20 now how can we interchange these two values so I have to get 20 into the a similarly I want to get 10 into the B so let us
92:40
Speaker A
use a temporary variable called C take another variable called C now what I will do first step I will assign a value into the C okay then what will happen happen a value into the C now C value
92:55
Speaker A
becomes 10 second this is the first step second step I will assign B value into the a b value into the the Second Step so I will assign B value into the a then what happens the 20 will assign to the
93:11
Speaker A
a now a value will replace with the 20 then third step I will assign the C value into the B third step now if iend C value into the B then what will happen C value is current value of C is what 10 10
93:26
Speaker A
will assign to the B now this will over replaced with the 10 now after executing these three statements now what is the current value of a 20 current value of B 10 the values are interchanged or not yes this is called swapping okay so by writing these three statements initially you take
93:50
Speaker A
a value and B value something after execution of these three statements if I print a value and B value the swapping is done okay this is the most common very popular solution everywhere you can see this but I don't want to do like this without using temporary variable I don't want
94:11
Speaker A
to use this temporary variable so without using this temporary variable just by using operators arithmetic operators okay just by using AR Artic operators without using any temporary variable just by using arithmetic operators you can do that swapping technique swapping of two numbers
94:34
Speaker A
without using temporary we so you guys can try this think about this logic how can we do this and if you Google it you can find the solution in many places there are so many solutions are there without using temporary variable almost four to five different solutions are there but
94:53
Speaker A
I ask you guys can guess and you guys can check the logic and accordingly you can try this and for the solution I will share a small video here I will just share small video link here you can
95:08
Speaker A
just go through that video and you can understand the solution I have given almost three to four different ways we can do the swapping okay so you guys can use whatever you want that is up to you don't ask me now okay you can use any way other than the temporary variable there are four to
95:27
Speaker A
five different ways are there you can find out at least one or two ways you guys can at least one okay any approach is fine but other than using temporary variable so don't use temporary variable other than using temporary variable that approach you can try any other approaches you can use plus
95:46
Speaker A
minus operators you can use star/ operators a different type of arithmetic operator you can can use combination of those operators but you don't want to create any other variables Just A and B only two variables you have to create and you should able to swap no temporary variable
96:04
Speaker A
without temporary variable Just A and B only two variables we have to create and we have to do the swapping so here I have given the link this is a link you can just go through this link okay
96:17
Speaker A
and uh I have explained all the approaches in this video first you try yourself okay and if you're not able to get the logic then go to the video you can understand that logic and you guys can Pro that okay so here in the notes I provided this link solution you guys can refer this this is
96:40
Speaker A
a assignment for today's session and slowly I'll try to increase assignments also and day by day because once you start learning more Concepts I will try to give more number of assignments fine that's it so this is the topic for today and tomorrow we'll continue with another topic okay
Topics:Java operatorsJava expressionsarithmetic operatorsrelational operatorslogical operatorsassignment operatorsincrement operatordecrement operatorternary operatorJava programming basics

Frequently Asked Questions

What is an operator in Java?

An operator in Java is a symbol that performs a specific operation on one or more operands (variables) within an expression.

What are the main types of operators in Java covered in this video?

The video covers six main types of operators: arithmetic, relational/comparison, logical, increment/decrement, assignment, and conditional/ternary operators.

How do arithmetic operators work in Java?

Arithmetic operators perform basic mathematical operations like addition, subtraction, multiplication, division, and modulo on numeric data types such as int, float, and double.

Get More with the Söz AI App

Transcribe recordings, audio files, and YouTube videos — with AI summaries, speaker detection, and unlimited transcriptions.

Or transcribe another YouTube video here →