Java Essentials - Real Type data in java
24K views
Nov 28, 2024
Java Essentials - Real Type data in java Watch more Videos at https://www.tutorialspoint.com/videotutorials/index.htm Lecture By: Mr. Arnab Chakraborty, Tutorials Point India Private Limited
View Video Transcript
0:00
In this video we are discussing real type of data in Java
0:06
We know that in case of real type of data where we can have the fractional part of the data
0:11
In case of integer we cannot have any fractional part but in case of real type of data
0:15
we can have the fractional part and it has got two different representations in Java
0:21
So in Java there are two data types that can hold the real type of data and or they're
0:26
nothing but also they can be called as a floating point data. to represent fractions. And there are two data types are float and double and
0:36
variables can hold a positive and negative type of data. So we're having two
0:41
data types, one is the float and another one is the double, float with all
0:44
letters in the lower case and double with all letters in the lower case. So
0:49
float and double. So there are two types of data types are there. So with the help of
0:54
which you can define variables which can hold real numbers. That means the numbers
1:00
the fractional part for the flow type data we are having 32-bit single precision
1:06
that is iE 7504 floating point format in case of flow type of data we are having
1:12
the 32 bits will get occupied will get reserved in the computer memory as a storage to hold that real type of data and these 32 bits will be divided into three sections one
1:24
bit for the sign for the significant next eight bits for the sign that is
1:29
for the bias exponent and then we'll be going for the significant part so these
1:34
are the divisions of this 30 bits that is 1 plus 8 so 9 so 32 minus 9 is
1:42
23 so 23 beats for the significant or mandatory presentation so this i triple is a
1:50
respective floating point format which is universally accepted worldwide so that is the
1:56
institute of electrical and electronics engineers and the prototype name is iuplea 754 the double
2:05
type data are holding 64 bits that is a double precision it pylis 754 floating point format
2:12
representation and this 64 bits will be divided into first bit for the sign for the
2:18
significant next for the exponent how many bits for the exponent 11 bits for
2:22
the exponent so one plus 11 we're having 12 bits so if you subtract 12 from this
2:28
64 we are getting 52 bits for the nantessa or the significant
2:33
representation and that is actually it has been depicted in this particular documentation that is the IEE floating point format So let us go for one practical demonstration with the help of which we can discuss more about this real number representation in our Java
2:51
So here is a demonstration for you. In this Java program we are going to deal with the float and double data type variables
2:59
We have defined one variable my float of the type float and we are assigned. and we are assigning 50.26 to this my float variable. So to convert this 50.2 to 6 to the
3:10
float type we are writing either capital F or small F at the end of the number to
3:15
represent that it is a float data and then we are printing the value of the my float
3:20
variable so the outcome is our 50.26 in the next example 50 and 3 individually
3:27
they are integers but I want to do some float division between them. So
3:32
so that's why here we have done this type casting so type casting to change
3:37
integer to float and as a result of that we will be getting and we'll be
3:41
observing fractional part in our quotient after doing the division so that's why
3:46
16.666666 is the respective answer and that if that has been assigned to
3:52
my float and my float has got printed here we having my double in case of my double we know that in case of double type of data types will be having eight bytes of memory space will be occupied to hold this respective variables value so in
4:09
case of float four bytes in case of double it will be eight bytes on this
4:14
particular variable we have written minus 0.2356 so here we can use capital D
4:22
or small D to represent that it is a double data but by default it will be of the type of double so I'm
4:28
going for the execution I can find that my double is having the value that is minus 0.2356
4:34
here we're doing some division operation so this particular 22 we're representing this number 22 in the terms of double so that's why we can write
4:46
capital D or small D after 22 and we're expecting that this particular quotient will have
4:52
the fractional part here so 22 D by 7 so converting 22 as double and that's why we're
4:59
going to get our fractional part in our quotient that is 3.142857 1 4 and so on
5:06
so in this way we have shown you that how to deal with the float and double type
5:11
variables in our Java code thanks for watching this video
#Java (Programming Language)
#Programming