Java Lesson-1.0.1.4

ravicplk

Member
Oct 18, 2007
4,120
1
0
39
Sri Lanka
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.


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..


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.
 
Last edited:

ravicplk

Member
Oct 18, 2007
4,120
1
0
39
Sri Lanka
ooooooops..
little addition. i forgot to say that when u are u using float data type u have to put a lower case "F" after the number,
"there are some zooming problems in this video..its my first one ne..i ll try to do better in the future,
 

henderson

Active member
  • Nov 24, 2007
    3,150
    2
    38
    Senior Executive, Goldman Sachs
    Great lesson, keep up the good work bro.

    And I like to add some more small points to the lesson

    And always you can define numbers as follows,

    long lng = 1034L;
    double dbl = 324.322D;
    float flt = 332.45332F;

    and in characters if you need to define '\' character

    you have to define it as
    char ch = '\\';

    and for unicode characters
    define them like
    char ch = '\u0021';
     

    ravicplk

    Member
    Oct 18, 2007
    4,120
    1
    0
    39
    Sri Lanka
    henderson said:
    And always you can define numbers as follows,

    long lng = 1034L;
    double dbl = 324.322D;
    float flt = 332.45332F;

    and in characters if you need to define '\' character

    you have to define it as
    char ch = '\\';

    and for unicode characters
    define them like
    char ch = '\u0021';
    thanks for the addition ayya..thanks again
     

    TΞΞNSTAR™

    Member
    Mar 19, 2008
    15,866
    42
    0
    StuCk In My AnGelZ HeArT!!!
    henderson said:
    Great lesson, keep up the good work bro.

    And I like to add some more small points to the lesson

    And always you can define numbers as follows,

    long lng = 1034L;
    double dbl = 324.322D;
    float flt = 332.45332F;

    and in characters if you need to define '\' character

    you have to define it as
    char ch = '\\';

    and for unicode characters
    define them like
    char ch = '\u0021';

    tnx broo....
    :D:D
     

    Malinga

    Well-known member
  • Jul 20, 2006
    61,301
    1,013
    113
    ravicplk said:
    hmmmm...seems to me is that likeness to these lessons got decreased
    if there are any suggestions please mention

    comments nodammata lessons balanavane kattiya. registered user la vitharak namai anith ayath balanava athi. oyaa vade digata ma karagena yanna malli :D