Char and Boolean primitive type

A char is used to store single character  and occupies two bytes of memory, or 16 bits. As char store single character but still  occupies two bytes. The reason is that it allows you to store Unicode characters.


Unicode
:- Unicode is universal encoding standard for different languages, Each character or letter, number, or symbol is assigned a unique value that applicable across any programming language.

In the English alphabet, we have the letters A through Z. Meaning only 26 characters are needed in total to represent the entire English alphabet. But other languages need more characters, and often a lot more.

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

package com.ekumeedhelp;

public class CharType {

public static void main(String[] args) {
char charValue = 'A';
char unicodeValue = '\u0045';
System.out.println(charValue);
System.out.println(unicodeValue);

}

}



Boolean :- A boolean value is either True or False, Yes or No, 1 or 0. In Java terms we have a boolean primitive type and it can be set to two values only. true or false They are actually pretty useful and you will use them a lot when programming

package com.ekumeedhelp;

public class BooleanType {

public static void main(String[] args) {

boolean trueBooleanValue = true;
System.out.println(trueBooleanValue);

boolean falseBooleanValue = false;
System.out.println(falseBooleanValue);

}

}

Share this

Related Posts

Previous
Next Post »