Non-Numeric Datatypes in Java: Char, Boolean Datatypes

Non-Numeric Data types includes Char and Boolean. It has its own respective Wrapper Class i.e. char or boolean.

In Java, there are two Non-Numeric Data types, let see one by one

1. char

Char data type used to store single character in memory. It uses 2 bytes storage space.

char data type is a single 16-bit Unicode character. Minimum value of char datatype is '\u0000' (or 0) and Maximum value is '\uffff' (or 65,535 inclusive).

Example of char Data type

package BestJavaTutorial;
class Simple
{

public static void main(String args[])
{
char ch='m';//char variable value should be in single quote('') and variable must contain only one character.
System.out.println("Value of a: "+ch);
}
}

run:

Value of a: m
BUILD SUCCESSFUL (total time: 0 seconds)

2. boolean

Boolean Data type used when we want to test a particular condition during the execution of the program. There are only two values that a Boolean type can hold: true and false.

Boolean type is denoted by the keyword Boolean and uses only one bit of storage. Default value is false.

Example of boolean Data type

package BestJavaTutorial;
class Simple
{

public static void main(String args[])
{
boolean a=true;
System.out.println("Value of a: "+a);
}
}

run:

Value of a: true
BUILD SUCCESSFUL (total time: 0 seconds)
Previous Post Next Post

Contact Form