hey everyone I hope you all are safe and doing good so in the previous lecture we have seen four uh fundamental data types or primitive data types in Java that is bite short intent long now we are left with four more data types that is float double care and Boolean so those remaining data types primitive data types we will be discussing in this lecture right what is float double car and Boolean so let's first start with float data type see we deal with floting Point numbers as well it's not like that we we always deal
with the whole number integer number like 10 1 Zer or any number 9800 no we deal with floting Point number as well those numbers are having fractional part like in uh when you are calculating your average or your marks maybe like 98.9 n something like this so these are floting Point number having a fraction part right in scientific calculation also we need floting Point number in financial calculation as well we deal with these numbers like a price of something in Billing also we deal with fractional numbers right there is not always a whole number in
every you know everywhere right so we have two data types as well primitive data types in Java and these data types deal with floting Point number we can represent these floating Point number with those data type what are those data type one is float and one is double okay now the float the size of this data type float is 32 bits means four bytes in memory would be allocated so if I write something like this if I have like a variable of type float suppose Max is equal to 98 9 what is this F I'll
tell you so this is the variable for this variable how much memory would be allocated 4 byes would be allocated 32 bits in memory right the range is approximately this for flow data type - 3.4 e 382 + 3.4 e 38 now this e is what it's in scientific notation basically when you represent e it's like - 3.4 that is into 10 ra to power whatever is there after e so here 10 ra to power 38 only something like this this is how we denote this number so these are very either very small number or
large number having many zeros so rather than writing so many zeros maybe 10 20 30 zeros you know in computer they denote it in in this s ific notation having e something like this right so this is the range Now default value for float is always 0.0 it's F see at last we have written F so to specify that it is a float number the suffix we will add as F small F or capital F right why we need to add suffix that also I'll tell now one more thing is there in floating Point data
type Precision means after decimal like 98. 99 after decimal how many decimal digits are there so if a variable is float type then after decimal it can store six to seven decimal digits in some uh uh laptop you will see like some machine is six in some machines it will show till seven decimal digits Precision so like 9 9 1 2 3 4 5 something like this so till 5 in float it will represent the number till five because if floating Point numbers we cannot represent a floating Point number accurately because after this decimal there
can be many many many many many numbers sometimes when you do something like this 10 to uh 10 divid by 3 so it would be 3 3 3 3 3 3 3 something like this Infinity so we cannot represent a floating Point number accurately so obviously this float and double are also not accurate one right but definitely these are more accurate than the whole numbers right and see this is about float now I'll show you with example as well now the what about uh double data type if we have a double let me just show
you that slide first so this double data type occupies how much memory 64 bit memory means eight bytes this data type so if I write something like this like double and if I write marks same example I'm taking is equal to 98.9 and at last we write D small D or capital D and in float we write small F or capital F so this is spec I am specifying that this is a double so this marks will take how many bits in memory 64 bits this variable default value is 0.0 D or default value for
float is 0.0 F now what is this default value this default value would be assigned to instance variables only this thing we have discussed when we were discussing types of variables instance variable local variable static variable so instance variable or class level variables those variables only uh if you don't initialize those variable then the compiler will give will automatically assign some default value to those variables but the default value would not be assigned to local variables if you don't initialize a local variable or if you declare a local variable and don't assign any value and
if you're using that local variable then it will give error so this default value is just for instance variables in previous also case also when we were discussing bite short intend long the default value of all these four data types is zero and that also will be for only instance variables not for local variables right range is this one approximately 1.7 e now 10 ra to power 308 see how many zeros 1.78 10 to power uh 38 so this is range of double now after decimal after decimal in double the Precision point is 15 to
16 decimal digits so after decimal we have almost 15 to 16 digits so definitely this number would be more precise than a number number which is having only six to seven digits after decimal yes or no I hope you're getting this point so that's why if you need more Precision then we we use double because it is more precise than float because of this reason also it is having 15 to 16 decimal digits after uh decimal point right so that's why because of this reason also a by default for floating Point number in Java the
data type is double by default it's double so if you write something like this if you write float F or float marks is equal to 98.9 and semicolon what do you think it will execute or uh will it give error it will give you error I'll show you practically also why so because I have told by default these floating Point numbers would be considered as double now compiler will think that it is double and here you are providing float so it's wrong right because Java is a statically typed language so if you are providing float
here data type then here the number should be float so you can write here F or capital F just to tell that yeah it is a float not a double right so let me just show you you these float and double with the help of some practical examples so we are in our ID intell idea and in the first project here we have in the source let's create a new Java file and that is we can say like the name is floating Point demo or you can take any name right let's take a first of
all float variable and suppose marks I'm taking equ Al to 8.99 right see you you you see the red line here provided is double but required type is float means you have provided a double type here so by default the floating Point number would be considered as double so let's not remove this error first let's just display uh make a function method here that is display and there we are just printing the marks right have to print that thing I guess uh you know now because we have used this thing many times so after this
display just within the same class I'm writing or let's create this time a different class class and uh let's make this class name float test that's it and here you are writing like public static void main so to access the attributes or the members of this class we have to create first object of the class name of the class is floating Point demo and suppose object is I'm taking obj is equal to new and this is the Constructor now with the help of obj have to call the object name dot operator and whatever you want
to access marks or or the method I want to access display the method I just want to call this method this is Method calling we'll discuss about methods more don't worry so just the object the method name these uh brackets round brackets and semicolon so this is what calling this is what definition of this method we are defining what this method is doing right now let's run this and see what output we are getting here okay sorry it was it's running integer demo so here we have to run the current file that is floating Point
demo do Java possible lossy conversion from double to float so from double to float okay to float is fine but where is double so this is considered as double by default every floating number so if you want to make you have to make the specific that this is float either capital F or small F at this point of time you will not get any error and this would be executed marks you will get here so one point is this you need to take care but if I write something like this if I write simply 98
see at this point of time it will not give any error let's run this and I'll show you it will print 98.0 right so 98 is like it will automatically convert this into float this is implicit conversion 98 is like integer and this is float so integer is small float is more so it will automatically convert this into float right uh float is larger so from smaller to larger that that there could be automatic conversion right that's why it is not giving any error but if you write 0.9 at that this point of time it
will consider it as double and double is Large and Float is small so this conversion cannot be possible automatically so one point is this now next point is if if uh you can do something like this like 9 F or I don't want to add F here now what is the second way to remove this error you have to think and try this out don't just add here F there's a second way also to convert this into float and what is that way just pause the video and try this out so I hope you have
done this the second way is what we can do is we can typ cast this you want to typ cast this into float so just write down in bracket here float now this is also fine let's run this and I'll show you the output here it will give you 98.9 but rather than this obviously we should we will follow just write down here f as a suffix this is more you can say convenient to right right now now next is let's take double and in double I'm just writing uh suppose maybe any any number suppose
I take a variable price and I'm just writing here price is this much only and simply I'm printing price so what do you think it will give error or it will print whatever the price you have given it will not give any error see because this is by default in literal and it will convert to into double because this is smaller this is larger so smaller to larger is POS possible so it will not give any error if I write here 0.9 in that case also it will not give any error because by default floating
points are considered as double right so you don't need to specify third ways you can write here D also or capital D also so we are specifying that by this by this adding this suffix D that this is a double but if you not add D that is also fine but better to add this would be recommended just to differentiate right so let's run this and it will show you both the float the marks and the price so this are this is some some basic uh detail about float and double how you can use them
now next if you use something like this if I use like double and I'm using a variable like X is equal to I'm writing here something like this 1.7 and and E and 308 this is what I'm using this is the mix max range of this double and we will just print this x that's it so let's see what output you are getting here see this is printing something like this right and if you write a number something like like this like uh 1.7 or uh if suppose I want to print this type of number
let's run this and see what output you are getting so this this has been represented by in this form ex uh scientific notation form so rather than representing so many zeros and all this number better to use computer use this scientific notation right so that's why the range of the float is given in this scientific notation e notation but you don't have to go into that much deep about and exponent how to find out this magnitude and all that is a different concept you just remember the range of the float and just these simple things
how to write down how to declare a float a double variable and all now next next thing is what if I write something like this see if I write a number like float a number is like f is equal to 1.1 2 3 4 5 6 7 8 9 10 1 2 3 4 something like this and semicolon and it would be F and now I want to print this F so what do you think what value will be printed let's save this and now let's run this after decimal see it will print only after
decimal it will print only seven digits seven decimal digits right so I told you the Precision in float after decimal it will print six to seven uh digits right so it is not this number is not precise and even after six we have seven but it is eight it is printing eight so the number is rounded off this is rounding because the next number is greater than five so this number becomes seven becomes eight so this is rounding right now if I take this float sorry if I take this uh one more variable double and
d and same [Music] I'm so this is the number I have in double and same I'm printing this this also D also so what do you think what it will print let's run this and see in both F and D what you are getting see after here we are getting only seven decimal here we are getting after this up to uh 16 decimal so 10 11 12 13 14 15 16 up to 16 decimal point right so 1 2 3 4 5 and the six has been rounded off and it becomes seven so the numbers
are not accurate although the number is this but we are printing in float this and the double is printing this only so the number is not accurate I mean when you want more precise calculation then we don't want to use float and double right now in that case there is one class in Java that is big decimal so this is one class in Java that is big decimal this is something like this big and decimal the name of the class is this it's not this big and there's no space and D is capital and decimal
so this will be used used when you are dealing with when you want to use in more precise calculation if you want to do rather than using float and double this will be later we'll be discussing later right but see the thing is double is double is what more precise than float that's why by default we use double so one assignment is for you now uh you have to convert whatever your height is in feet it's 5 5.3 5 .6 5.8 or 6 in feet you take your height in feet and convert that into meter
and then print that thing so pause the video and try this out right now so uh what you need to do is basically you have to convert feet into meters and the formula is uh 1 ft is 1 ft is equal to 0.34 8 m so what is your height suppose your height is 5 .3 ft so let's multiply this 0.3048 like this and then you have to print right so take your height in feet let's take in a variable double variable and then print the result so pause the video and try this out so
I hope you have done this let's just remove everything from here and uh let's take height so we will take in double and a variable my height and suppose I'm taking in feet something like 5.3 no need to write down here D or F or obviously not F you'll write if you write we can write D here because it's double okay now you have to convert this into meter so in display we can have a variable like the double maybe result and then result is equal to this whatever the height 5.3 into 0 3 0
4 8 this is the case now semicolon so don't need to put here this if you want to put you can just put here but you don't want to put these brackets you can just leave it something like this and simply just print here height in meters is whatever the result is that's it and we have fold this here in this float test class now if I show you let's just run this and let's see what output we getting so it's 1. 6154 right if you take this float if you take this float suppose F
and when you perform the operation let's run the S see what output you are getting see the same thing you are getting here right so see in this program we have two classes this and this so basically you will get here in out here you can see in production first project so see basically there are two classes so two do class file would be there so if you want to check you can check out so here I have in my PC users in this user I have idea projects and there I have first project and
there in Source see we have floating Point demo so rather than Source we check out out production first project and see floating Point demo docl class and Float test do class so directly you can run from here also from command prompt if you want to run from command prompt the one um student was asking this question that we write programm in ID and can we run in that command prompt yes you can run in command prompt let me show you how you can run let's just open this in CMD uh command prompt and my main
method is in this class float test so you have to run this class right but first directly if I run here Java C and Float test dot Java it will give error see file not found because the path is see the path it is searching in user in this user and that's it but my file is within this user then idea project then first project then out then production then first project my file is here here my do class file is there so you have to copy this complete path contrl C and here we'll be
out from this path and we have only C drive so CD and control V whatever the path you have now I'm I can find my compiler will find the do class file so now I can run Javas C and this okay it's Java C see now error is again error file not found because we are in out production so here we have do class file we don't have our Java file so from here if you want to run if you want to run our Java file then you have to come out my Java file is
here in SRC folder so you want to run you want to compile this Java file right you want to compile that Java file floating Point demo and the name of that Java file is floating Point demo it's not floating like that dot class file let's just paste this and I think we are done we are in this first project now suppose I want to paste here this let's clear the screen CLS so we are in first project and SRC so if I run if I run my Java C it's not the name is not float
test the name is floating point and demo dot Java now it will not give any error right now suppose from here only we want to run and the command is Java and in which file we have in which file we have main float test so we have to run float test let's run this and see height in meter is this you got you can run this from CMD also but the thing is you have to set the path where you have your source file and then compile and then you can just run that right but
make sure see now the class name I'm giving this and for compiling I am providing this name because in this class I have my main so definitely for jvm jvm will run entry point is main so jvm will run this class only you have to provide this class name dot class file name right okay now this is all about float and double this is I think you have done this thing also now let's discuss about character data type so next data type is care data type so this care data type occupies how many bytes two
bytes in memory or 16 bits you can say right now it is used basically to store a single character suppose I want to store this a so yes we can store a or one in single code and always we represent this in single code or a symbol like hash or space this is space so to store a single character we use care data type now it it will take two by in memory the range is 0 to 65535 now see there is no negative number so car is represented in the memory as unsigned integer internally
obviously it is a character here but intern internally it is represented as an integer or more specifically if I say then unsigned integer see from 0 to this is the the range of car character car default value for this is this uh is it is something like Unicode and uh U stands for unic Unicode encoding but let's just hold this point here I'll discuss everything about this thing also don't worry now this characters are stored as 16bit Unicode characters so what is this uni code I'll tell you don't worry right now first of all let
me just tell you one thing about character internally how to how to declare or Define this we write something like this like care this is the data type name of the variable suppose I'm taking here uh grade and your grade is suppose a now this a would be stored internally as an N sign integer now why maybe you are thinking why 65,000 character or this range because generally we only see like alphabet A to Z or A to Z small or one to or 0 to 9 numbers and some special uh characters like hash or
special symbols hash and all these kind of symbols so why this much range right see there are so many languages in the world Japanese uh French or many languages even in India like Tamil Telugu and each language has its own character set on symbols and characters it's not like that we know only ABCD and in Hindi a these kind of things and that's it no there are so many languages every languages have their different different characters and symbols right that's why the range is this much to represent all these characters from all the languages across
the world in computer or in digital devices that's why the range is this one right now I have told you internally the character is to be stored as integer so this mapping from character from a character to this integer it is defined by Unicode character set there is Unicode character set like Sky you have you have heard about Sky character set American Standard code for information interchange this is having small range but there is a uni code this is internet International standard code so Unicode this is this basically contains standardized collection of all the characters
including letters digits symbols control characters or emojis from all across the languages from all the languages AC Ross the world this character set I'll show you this character set also don't worry right so these are some specifications so now there are different implementation of these Unicode character set you heard about utf8 UTF 16 UTF 32 Java use utf16 encoding scheme to convert character into that particular uni code character set uni code character right just to represent that thing in computer or digital devices so Java uses this uni code UTF 16 encoding scheme in this what
will happen let me just show you in this Unicode 16 encoding scheme this is basically an see encoding scheme which provides a unique number unique number or you can say it's a code point for every character for every character whe whether it's letter digits symbols or another some special symbols or emojis for every character it provides a code point across different writing systems symbols emojis why so allowing for consistent representation and manipulation of text in computer and digital devices just to represent consistently all the character from all the languages across the world all the symbols
in computer and digital devices okay so they provideed encoding scheme this is just an encoding scheme UTF 8 is also there UTF 32 is also there java use this scheme Java language now what is this code point every character is given a unique code and the format is this U plus x x x x this XX this is a hexade decimal number for every character this code is provided this is a code point right like I'll tell you this I'll show you this on my laptop this uni code and all but just for suppose for
a they provide this thing u+ 0 0 I think it's 41 maybe it's I'm not uh I'm wrong but we'll check this but most probably for a the scheme Unicode character is encoding scheme is this 041 the hexade decimal number is 041 so whatever the character that would be converted into this by the uni code character set or by this UTF encoding scheme into this and then this would be converted into binary like 0 0 0 0 for four we like 0 1 0 0 and for one it's 0 0 0 1 so this is
equivalent binary and this is how to be stored in computer memory so it's easy to convert this hexadecimal to Binary as you can see this is to be stored in computer memory in binary form obviously and the decimal equivalent for this binaries we know that is 65 so when you print this you get you get 65 right so now this a this can be represented by this a by this literal a by this encoding scheme and we write this not like this we write this something like this slash small U 041 something like this this
is what we can say it's uh that back slash or character so this is U for uni code and this is the hexadecimal form or this can be represented by the decimal number that is 65 right so we can assign to a character to this literal also uh Unicode character set also or this decimal also how to initialize a character by in these three way I'll show you with the help of practical so in this source file let's create a new Java class and uh let's name it care demo right and there we are taking
a care character suppose and your grade is equal to a and let's take Define a method here display and there we just printing grade we are printing this grade and at this point of time within the same class within the same class I am writing public static void Main and let's create an object of the scare demo that is suppose obj only is equal to new and the scare demo this is the way we create object and have to call the method obj dot display let's run this and see what output we are getting here
see is printing grade is a because we have given here grade A now you can't say something you can't write something like this because there are two characters here but with a care data type you can store only Single Character too many characters in character literal so this will not work this will give you error and if you remove these single codes this will also give error see cannot resolve cannot resolve symbol a means it you know compiler is not able to identify what is the a so you have to put single quote right you
have to put here single code so rather than a I can just write down here space as well so if I print this then it will print nothing just a space it will print like there is a space but if you don't write anything here if you don't put any space then also it will give you error empty character literal that is not allowed or one also you can write down here so this is also fine now one is a number but this would be considered as a character because we are putting this in single
code now what uh now uh next thing is any symbol also we can put like I'm printing here this at theate so this is also fine this will print at the rate see right now see in Google if you search Unicode table and the first link is there so once you click on this link you will get here list of Unicode symbols all the symbols just ignore these ads and see the first is null right and uni code for this is U plus 00 0 so by default character the default value of character is this
only it will not print anything if you want to go for a see the uni code for Capital a is U + 0 0 41 and if you want to search something more about the say you can just click here and see uni code number is this HTML code is this so from here you can find out 65 is the decimal of this a CSS code and some more information about this a but we don't want to go for this information we just want the uni code so there are so many symbols on this table
for 1 2 3 4 also there is uni code 0 0 31 is for one and there are many symbols as well see for every symbol you have some Unicode uh character Unicode number right you can just scroll down and there would be many symbols here for every symbol see for Hindi words also a it's U plus 0 905 for Hindi words also for these also see so you can check out for there are many symbols so if you are a Tamil or Telugu student then also you can check out for your language also there
are many uni code symbols and you can represent these symbols right now if I want to represent see I want to represent this uh I want to write here the unic code of a so grade is equal to how you write you write this slash then U small U then 0041 this is how we can assign initialize a care with Unicode number also it will print a only let's run this and I'll show you because this is Unicode for a this is Unicode for a character a and it will print definitely a only one more
way is there if I write here rather than uni code if I write here the decimal for a is 65 that will also work fine let's run this and I'll show you it will give you a only C because 65 is equivalent to in character a so this will give you a only right if you want to print something else like uh if I want to print Unicode of let's check the Unicode table and I want to print C this C so this unic code for this C is it's 0958 so let's print this U
2 0958 so let's run this and see what output you are getting here see it will print C so anything you can print but this is invalid if you write here capital u this is invalid you can't here write capital u it should be it's illegal Escape character in character literal it should be small U it represents Unicode and this is also illegal you have to write down proper Unicode uni code uh sequence this is illegal unic code escape sequence so it's 58 I guess and if you want to print here like the maximum value
655 what is there 655 35 so this is the maximum value let's print this and according to this value what is there it's nothing so for 65535 it's printing nothing or maybe the symbol my editor is not going to support that symbol is there or you can check out what is the equivalent character for this 65535 so you can check out we have chat GPT equivalent character for this the value this corresponds to the character okay this one this is special character known as last character in the Unicode range it's basically a non character so
that's why it is printing something like this right okay we have chat GPT now you can ask from chat GPT and if I print something like this suppose if I print here 6 5537 see it will give you error provided is int and required is care so it is considered this as int but I want this to consider consider as character so I can just type cast this now what it will print let's run this and I'll show you I think it will print nothing it will go for wraparound concept but it will not print
anything because in uni code after the maximum after the maximum we again go to here after 6 5 53 5 we go again go to zero then one then two and something like this and these symbols are nothing they will not print anything but if you add something like uh if you add here suppose I want to print here 70 so let's run this and see what it will print this is see care so according to care it will not give any error although it is out of range of care but it will go for
the wraparound concept right you have type c this into care and this will print double quote symbol so you can check out in this after 65535 it's 65536 37 like this 38 39 and like this if you count then this would be 655 70 so that's why it is printing again 0023 this or you can print here by 0023 as well rather than 70 by the encoding scheme right so this is how wraparound concept also comes in care as well so same if you didn't get that wraparound concept let me just show you here so
this is for character if we have zero so it would be 1 2 3 something like this and there's no negative so here here we have 655 35 655 34 right and once you go for 655 36 once you add one then again it would be zero then two then three then four right so for 70 it would be something like here and for 70 it will print single code that sorry double code right and see it is also fine if I write something like this in X is equal to a and if you print
here x what do you think what it will print just pause the video and search uh try this out if you print this x then it will print here the integer value for this x the decimal value that is 60 5 right because characters are internally stored with help of integer in form of unsigned integer so there is R type is in so it will convert this into 65 and 65 would be printed here so I have told you we can assign a care in three ways like if I write car or suppose I write
here something like this uh car and care one variable name is a now if if I write like care and get one more variable two that is 65 and one more care that is ch3 is equal to with with uni code with u and 04 1 so in this three way we can assign so if you print K 1 k 2 K three what you will get so we are printing all these three characters so all these three characters will be printing a only so you can initialize a care variable in three ways initializing with
a care literal this is the car lateral initializing with an INT lateral this is int lateral and initializing with a Unicode escape sequence this is Unicode escape sequence this is this is how you can do this thing so now one assignment for you is you have to print minimum value and maximum value for a car type using rapper class there's a rapper class for car that is character so use that rapper class and print the minimum value and maximum value for car type pause the video and try this out right now so I hope you
have done this thing let's take a care my care main value this is the variable name is is equal to we are taking the class name is see the character dot minan value same for maximum value we have max value so maybe you are thinking let's just print now these two values so let's just print let's see so I'm just printing my care first main value and then in next I'm just printing my care max value and we are calling this with the object let's run this and see you are getting output or not see
the symbols I mean nothing null type of symbols it is printing why so because this Min value would be something like some int value or something like this like zero or max value is 65535 and you are printing a character corresponding to that value that's why it is printing the character and the character corresponding to that value is corresponding to zero the character is null so nothing would be printed corresponding to that 65535 maximum value the character is also not printable that's why you are getting that output but if you want to print the integer
value so how you can print that thing pause the video and you can just try this out we have one method that is typ casting I have told you right so we can type cast suppose I'm taking one variable a is equal to and I will type cast this into int whatever the my care minan value and same I'm taking another variable B and there I'm typ casting whatever the my character max value is and rather than this if I simply print sorry let's suppose we print this thing also and we are printing both A
and B also so let's run this and see now this point of time what output you are getting here so first two output are null and null I mean nothing now next is 0 and 65535 so for that you have to convert this into int if you want to get that integer value right now one assignment for you is you can try this out you you have to store a uh the symbol hash you have to initialize this care variable all the three methods you have to use with the car literal hash with unic code
escape sequence for hash you can find out you have this table and from there you can find out what is the escape sequence for this special symbol hash or you can just ask from chat GPT and you can just use that symbol right and third is you use that U int lateral also which is corresponding to the hash so three character variable you have to Define you have to do this thing so I hope character is clear to you guys now we'll discuss about Boolean data type so before going for the Boolean data type maybe
you you are thinking in care we are able to store only Single Character so what is the use of this is there any special use or is there really a practical use of using C type yes it is sometimes we have to process the strings or the file character by character in some applications so there we use you have to store a single character so in there this character data type will be useful now reading and writing individual characters in file operations Al also right so their charactere will be useful some encryption schemes are also
there some encryption algorithm there you have heard about you know about cryptography and all or encryption and decryption if you don't know let me just tell you something about see in encryption this is for uh if I want to send my this data care so I will not directly send care I will just encrypt this in another thing maybe I'm using some formula and all and the C would be represented by like maybe X this y y and this y maybe Zed or r y something else something else right maybe s so this symbol this
Chara this message I will send and the sender I will send some key also like I have applied this algorithm to convert this into this and the sender will decrypt this using that key to care so that in between nobody is going to hack my message actual message is care but I'm sending XY z s so nobody's going to get this message so this is what we do in encryption and decryption there are some cryptographic algorithm also so individual character would be substituted with a different character so there we have to use the SC data
type to store a single character so that it's like there are many uses also for C after ending of a game you press any key so that also would be stored in a character data type right so there are many uses for character data type as well for character data type also now we have discussed character data type now we will see Boolean data type so now there are two values on and off or true or false log uh this logic values so to store this logic value also we have a Boolean data type in
Java you can store this true and false these two logic values or on and off with Boolean data type we can use true and false size is basically jvm dependent but typically it's one bit of information but we cannot we can't we can't say it's jvm dependent the size of Boolean data type default value is always false right and use is basically it's used for conditional statements and logic operations when you want to check some conditions in control flow statements in if else we discuss if else later if you want to check some condition is
it condition true or false then we use this Boolean data type right or we can use uh these data types in decision making in programs same like we want to make some decision like if I ask you or some student are you want to come in the class do you want to come in the class decision making in programs like same like f else if you want to make some decision based on some condition the condition is true or false then we use this Boolean data type right let me show you practically how you can
use this thing so in Source let's make make a different class file and let's name it Boolean demo right and there let's just store how to write there would be Boolean and suppose is Java easy is equal to false or is equal to suppose true yes it's easy so in display method I'm just printing the value of this variable is Java easy and then obviously to call this you have to create object of this class and how to create we know this is the method and to call this we write down obj dot display let's
run this and see what output we getting here so see it's true right and if you don't initialize this then by default the value of this variable would be it's false but it is the by default value would be assigned to the instance variables only and we know this is instance variable this is not local variable if I declare a variable here like Boolean is programming easy or programming fun and I don't initialize this variable here and suppose I want to print this variable also is programming fun so this see the error variable is PR
programming fun might not have been initialized you are using this variable you haven't initialized this so the default value would not be provided to this local variable this is local variable because this is within this method only this is instance variable because this is in class outside of any method so these are class level variable only class level variables are getting default values and it is true in all the cases like whether it's int or it's uh you can say that bite or short or long or float or double or care right see let me
show you the default values here default values for data type is given here for bite short int long it's 0 0 for long it's 0 L for float it's 0.0 0.0 f for double it's this for car it's null this okay string let's leave it and for Boolean it's false but this value is for instance variables only right it is from that Javas documentation only from oracle.com official website see they have specified this local variables are slightly different the compiler never never assigns a default value to an uninitialized local variable right accessing an uninitialized local
variable will result in compile time error so this is true for only instance variables you got it so that's why you are getting an error here so you have to initialize this it's like maybe false now you will get the output one is true one is false right so this this is mainly used in control statements or conditional statements where you using F else and for Loop also there we'll be using this so we'll discuss if else for Loop later and in expression also we can use this uh Boolean data type to control the flow
of the program based on some condition right so now let me just give you one simple example more example here let's just comment out these all these things here I take two varibles suppose I take int a is equal to 5 and or within same line also I can declare comma B is equal to within same line also you can declare multiple variables but that should be of same type int so a equal to 5 b equal to 6 no need to write down here again int otherwise it will give error so simply this thing
but it's not like that b is equal to 6.7 this is FL double this is in this is not allowed same data type is allowed and if I write something like this like Boolean result is equal to a less than b some kind of expression is there although it's not like logical type logical type of thing but still just to uh tell you just to show you how bullan variables or can be used in an expression so a less than b so this the result would be evaluated a is five b is 6 so less
than B it's uh operator relational operator we'll see operator in next video so five less than six yes it's true so in result we have true right now you can simply print the result here is a less than b and we can simply access the result VAR variable so let's run this and see it's true so Boolean variables are used in this case also you can store the result of an expression and later you can use that result to test some condition right so boan variables are this much only we don't have much in these
boan variables I hope you got this thing so you can see here the same example whatever we have taken Boolean the name of the variable is Java fun it's true and there is two Boolean variable now in conditional statements this is how we can use Boolean variables don't worry we'll discuss if else later if just the name of the variable is Java fun and the value is true so the condition is true so it will print enjoy coding now in logical operation also we can use naban see as result is a variable is Java fun
and this is logical and operator and this is not operator logical not is programming hard so is Java fun it's true the value is true and not is programming hard is programming hard is false and not becomes not means it becomes true so true and true true and true becomes true so it will result the it will print the result that is R we'll see these operators in next video Don't Worry right if you're not getting this thing leave it so when to use Boolean data types this thing also I've told you indicating the state
of a condition or a feature if you want to check any validation on an input like if you input the certain thing and if you want to check this if input is less than like I have input five and I want to check this input is like less than or greater than something the some value like suppose less than 10 or not I have entered five and I want to check this five is less than 10 or not input is valid or not based on some certain criteria in control flow also we use this thing
in comparison also we can use storing result of comparison for later use that thing I have shown you here right now okay now this is what the complete table we have flow double Caren Boolean so this thing we have already discussed now have to use the right data type you have to identify the data now you have to determine the which in which type of data you are working according to that choose the data type consider the range also in which range whether you are want to work on a small data or on a large
data So based on that you have to choose appropriate data type bent requirement if you want more precise thing more precise calculation according to that choose double if less precise you can use float as well right memory constraint also consider memory use especially especially for large data set like if you have constant on memory if you have less memories then better to use those short data types but if you don't have any constraint on memory like nowadays in our system we have you know a large memory we don't have such constraint so we don't care
much about data type right like even if store for a simple variable five we use int we can use bite as well but we use int right now okay there are some pitfalls uh with primitive dat types with specially floating Point precision so when you use some arithmetic operation when you do some arithmetic operation on floating point then it will not give you exact values it will give you some approximate values right so this thing you need to take care now overflow underlow I have already discussed right care versus string confusion care basically is store
Single Character and string is basically you can say there are many characters and string isn't double codes so you have to about string we will discuss later right so best practices for using primitive data types is what you have to use appropriate F according to your data appropriate type you have to use so that memory wastage would be minimum consistent naming the name of the variables should be descriptive and clear and you can use constant for frequently used and important values like for pi or max value you frequently use so make that constant using final
keyword and use that right so I guess you are now clear with the data types primitive data types all the eight primitive data types So based on this you can practice about this whatever we have discussed I'll give you assignment as well as quiz right so you can practice those question as well so now that's it for this video now I'll see you in the next video till then bye-bye th