Saturday, 8 March 2014

Data Types(Character & Boolean)

Today we will discuss Character data types and Boolean data types.
Character Data Types
This data type represents single characters like a,p ,m,s,r.To store char data type JVM takes 2 byte memory.It has range from 0 to 65535.There are no negative chars.The standard set of characters known as ASCII still ranges from 0 to 127 as always, and the extended 8-bit character set, ISO-Latin-1, ranges from 0 to 255. Since Java is designed to allow programs to be written for worldwide use, it makes sense that it would use Unicode to represent characters. Of course, the use of Unicode is somewhat inefficient for languages such as English, German, Spanish, or French, whose characters can easily be contained within 8 bits. But such is the price that must be paid for global portability.Unicode defines a fully international character set that can represent all of the characters found in all human languages. It is a unification of dozens of character sets, such as Latin, Greek, Arabic, Cyrillic, Hebrew, Katakana, Hangul, and many more. For this purpose, it requires 16 bits. Thus, in Java char is a 16-bit (2 byte)type.
To declare character data types we use a keyword "char".

It can be explained through a Java program
class Data
{

public static void main(String args[]) 
{
char ch, cH1;
ch = 83; // code for S
cH1 = 'A';
System.out.println("ch : "+ch);
System.out.println("cH1 : " + cH1);
}
}

Output:
ch : S
cH1: A

Boolean Data Types
Boolean data types represent  any of the two values true or false. JVM uses 1 bit memory to store boolean value . We use "boolean " keyword to declare boolean data types.
 It can be explained through a Java program

class Data
 {
    public static void main(String args[]) 
  {
    boolean b;
    b = false;
    System.out.println("b is " + b);
     b = true;
     System.out.println("b is " + b);
   }
}

output:-
 false
true

You all readers are requested to post your queries regarding these topics

No comments:

Post a Comment