ravicplk
05-21-2008, 07:57 AM
Hello there..how is everything going fine? Ready for the lesson? Then lets get started.
So before we move on to the Practical lesson lets check out those data types in detail.
First lets peek in to integer group,
In the integer group there are four data types.
What are they?
Byte,short,int,long.
I know u are having a question in ur mind nee.? Why the hell that there are four data types to represent whole numbers.
The reason is this. When u want to use whole numbers in various ranges, u have to move to different data types.
http://img375.imageshack.us/img375/4633/java2ix7.jpg
So now I think u know why we have to use four data types when u want to use integers in a program. If u want to use a big number u have to use long and like that u have to choose the best data type for u r need. And very importantly u have to think about the bit width too. If u want to store a number such as 12 choosing long wont be a good idea. coz it has a bit width of 64. its really long and takes up more memory. So u have to think about the memory allocation too,
Next one, the floating-point group, so what are the data types in that group. As u can remember two data types are there. “double” and “float”.
Another table coming up..
http://img375.imageshack.us/img375/6708/java3nk5.jpg
So I think no need to explain this, similarly to the integers u have to choose the best one for u r work considering the memory allocation and also u have to think about the range as well.
Actually a double can hold real numbers
±4.94065645841246544e-324d to
±1.79769313486231570e+308d
And a float can hold
±1.40129846432481707e-45 to
±3.40282346638528860e+38
Hmm that’s quite a bit of numbers there, I am having a headache just seen them.
Ok now. We have a group called character and the relevant data type is “char”
Char is used to store characters in a java program. Characters can be numbers,letters and etc.. I like to mention something I have read from a book. if someone have done C or C++ before they might familiar with “char” before. But guys don’t mess up. Coz the char in a C\C++ is not similar to char in java.
In C\C++ char is an integer type that is 8bits wide. But in java ,it uses Unicode to represent characters.(Unicode defines a fully international character set and this can represent characters from all most all the human languages). To do this Unicode needs a bit width of 16. So it is different from C and C++. That is an additional thing ok.
Now next one, Boolean group. In the Boolean group u have “boolean” data type. Actually what is boolean. He heeeeeee… a word with seven letters. That is also true. Actually boolean is used to interact with the logical values. It can only one logical value from two possible logical values.
As an example take a look at the statement given below,
“I will pass the exam” (will I???) ok now there can be only one result which can br happened out of two possible results.
First one this statement can be true. And also can be false. But only one can be happened. If I pass this is true and if I fail this becomes false. So it is like that, only two values in boolean operations. “True” and “False”
So that is a detailed description about data types in java. Now u have to do a small exercise to get familiar with these data types.
Here is the code.
class example
{
public static void main(String args[])
{
byte a=12;
short b=1234;
int c=14256;
long d=235678;
float e=12.34f;
double f=123.43;
boolean g=true;
char h='y';
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(e);
System.out.println(f);
System.out.println(g);
System.out.println(h);
}
}
And for u r convenience I made a screen video (thanks for malinga ayya for the software)
So that is today’s lesson. Got to go now, c ya later.
So before we move on to the Practical lesson lets check out those data types in detail.
First lets peek in to integer group,
In the integer group there are four data types.
What are they?
Byte,short,int,long.
I know u are having a question in ur mind nee.? Why the hell that there are four data types to represent whole numbers.
The reason is this. When u want to use whole numbers in various ranges, u have to move to different data types.
http://img375.imageshack.us/img375/4633/java2ix7.jpg
So now I think u know why we have to use four data types when u want to use integers in a program. If u want to use a big number u have to use long and like that u have to choose the best data type for u r need. And very importantly u have to think about the bit width too. If u want to store a number such as 12 choosing long wont be a good idea. coz it has a bit width of 64. its really long and takes up more memory. So u have to think about the memory allocation too,
Next one, the floating-point group, so what are the data types in that group. As u can remember two data types are there. “double” and “float”.
Another table coming up..
http://img375.imageshack.us/img375/6708/java3nk5.jpg
So I think no need to explain this, similarly to the integers u have to choose the best one for u r work considering the memory allocation and also u have to think about the range as well.
Actually a double can hold real numbers
±4.94065645841246544e-324d to
±1.79769313486231570e+308d
And a float can hold
±1.40129846432481707e-45 to
±3.40282346638528860e+38
Hmm that’s quite a bit of numbers there, I am having a headache just seen them.
Ok now. We have a group called character and the relevant data type is “char”
Char is used to store characters in a java program. Characters can be numbers,letters and etc.. I like to mention something I have read from a book. if someone have done C or C++ before they might familiar with “char” before. But guys don’t mess up. Coz the char in a C\C++ is not similar to char in java.
In C\C++ char is an integer type that is 8bits wide. But in java ,it uses Unicode to represent characters.(Unicode defines a fully international character set and this can represent characters from all most all the human languages). To do this Unicode needs a bit width of 16. So it is different from C and C++. That is an additional thing ok.
Now next one, Boolean group. In the Boolean group u have “boolean” data type. Actually what is boolean. He heeeeeee… a word with seven letters. That is also true. Actually boolean is used to interact with the logical values. It can only one logical value from two possible logical values.
As an example take a look at the statement given below,
“I will pass the exam” (will I???) ok now there can be only one result which can br happened out of two possible results.
First one this statement can be true. And also can be false. But only one can be happened. If I pass this is true and if I fail this becomes false. So it is like that, only two values in boolean operations. “True” and “False”
So that is a detailed description about data types in java. Now u have to do a small exercise to get familiar with these data types.
Here is the code.
class example
{
public static void main(String args[])
{
byte a=12;
short b=1234;
int c=14256;
long d=235678;
float e=12.34f;
double f=123.43;
boolean g=true;
char h='y';
System.out.println(a);
System.out.println(b);
System.out.println(c);
System.out.println(d);
System.out.println(e);
System.out.println(f);
System.out.println(g);
System.out.println(h);
}
}
And for u r convenience I made a screen video (thanks for malinga ayya for the software)
So that is today’s lesson. Got to go now, c ya later.