Search This Blog

Saturday, July 18, 2020

Char and Boolean data Type.

Char and Boolean data Type:


Char: Char data type is similar to String  variable yet, but it's in one sense in that you can store characters but in this can you can store  a single character.


Program:

public class ChaiAndBooleanMain {
public static void main(String[] args) {

char myChar = 'D';
char myUnicodeChar = '\u0044';
System.out.println(myChar);
System.out.println(myUnicodeChar);
char myCopyrightChar = '\u00A9';
System.out.println(myCopyrightChar);

}
}


Char Data Type:
       A Char occupies two bytes of memory or,  16 bits and thus has a width of 16. The reason it's not just a single byte  is that it allows you to store Unicode Character.


Unicode:
 Unicode is an  international encoding standers for use with different languages ad scripts, by which each letter , digit or symbols is assigned a unique numeric value that applies across  different programs and platforms.

   In the English alphabet  we have the letters A-Z . Total 26 characters. But in other language need more characters and often  more.

Unicode allows us to represent these languages and the way it works is that by using a combination of the two bytes  that char takes up in memory it can represent and one of 65535  different types of characters.



Boolean Primitive Data Type:  -

                            A Boolean values allows for two choices True or False , Yes or no, 1 or 0 . In java terms we have  a boolean primitive type and it can be set two values only. true or false . They are actually pretty useful and you will use a lot when programming.

Program:


public class BooleanDataType {
public static void main(String[] args) {

boolean myTrueBooleanValue = true;
boolean myFalseBooleanValue = false;
// Check whether customer age is over 21

boolean isCusotomerIsOverTwentyOne = true;
}
}



Primitive Type Recap:



public class MainRunner {
public static void main(String[] args) {
     
// byte
// short
// int
// long
// float
// double
// char
// boolean


}
}



No comments:

Post a Comment