Java Primitive Types
üThere are exactly eight primitive data
types in Java
üFour of them represent whole valued
signed numbers:
übyte, short, int, long
üTwo of them represent floating point
numbers:
üfloat, double
üOne of them represents characters:
üchar
üAnd one of them represents boolean
values:
üboolean.
Numeric
Primitive Types
üThe difference between the various
numeric primitive
types is their size, and therefore the values they can store:
Character
Primitive Type
üIt uses unicode to represent character.
üThe char type is unsigned 16 bit values
ranging from
0 to 65536.
üASCII still ranges from 0 to 127.
Example:
class
test
{ public static void main (String args[])
{
char ch1, ch2;
ch1=88;
ch2=‘Y’;
System.out.println (“ch1 and ch2: “ + ch1+”
“+ch2);
}
}
Output:
ch1 and ch2: X Y
Character
Primitive Type
Example:
class
test
{
public static void main (String args[])
{
char ch1;
ch1= ‘X’;
Sytem.out.println (“ch contains “+ch1);
ch1++;
System.out.println (“ch1 is now “ + ch1);
}
}
Output:
ch1
contains X
Ch1
is now Y
No comments:
Post a Comment