Till now you have learned about the following data types:
int
long
short
float
double
Now let us take a look at a data type that can be used to store characters.
Now, another important data type which we will be taking a look at is called as the Care Data type. Now suppose you wish to store single characters inside your Java program inside your variables, then you can use the data type. Care data type is used to store only single characters. These single characters can be letters or single digits or other special symbols. So for declaring a new Care, I say that care x equals two. And whenever I assign a value inside this Care, I always enclose the value inside single quotes. So I say single quote open and suppose to this XCAR, I wish to assign character A, then I declare it like this. Moreover, I can also write statements such as care y equals to and store some digits inside this. For example, I store the digit five inside this. So this five will actually not be treated as an integer, but it will be treated as a character that is a letter, English alphabet, or the single digit five. Similarly, you can also store some special characters such as the dollar symbol inside the car data type. So notice that whenever you are declaring a new character, you must always enclose them within single quotes and there is exactly one letter or one character which you can store inside the Care data type. So do you think that statements such as care B equal to CD are valid? Well, I just now told you that the Care data type can only store a single letter or a single alphabet. So statements such as these where you are storing multiple letters are invalid. And when you try to write these statements and run them, Java program will show you an error. Similarly, you can use other data types to store multiple characters about them. We are going to take a look at a bit later, but for now, remember that the Care data type is again a 16 bit data type type and strictly stores a single letter or alphabet inside it. Moreover, I can also store numbers inside it. But these numbers or these digits will be treated as a piece of character rather than integers or whole
Care data type is used to store single characters in Java programs.
It can store letters, single digits, and special symbols.
A new Care is declared by writing "care x = 'A'" with the value enclosed in single quotes.
You can also store numbers, but they will be treated as a character rather than an integer.
Statements such as "care B = CD" are invalid because the Care data type can only store a single letter or alphabet.
The Care data type is a 16-bit data type.
Other data types can be used to store multiple characters, which will be discussed later.
You have already seen data types which can store integers, decimal numbers or characters. Let us now move on to a data type called boolean. A boolean can store only one bit of data. Let us now take a look at how this happens and what is the utility of this data type.
We discussed the boolean data type, which can take only a true or false value. It can take a condition as an input and will return ‘true’ or ‘false’, depending on whether the condition is true or false.
The last of the data types is a byte. This is a data type of the smallest size.
Let us take a look at what it can store.
As you saw, a byte can store only an 8-bit integer ranging from till -1 .
You also learnt that the data types we discussed are called primitive data types since they are the building blocks for all other data types.
Let us now take a look at how we can initialize and use all these data types in Java.
You can download the following java file which will be very useful to you while watching the video. Right click on the java file and open it with IntelliJ. Please be careful with the name of the java file. The name of the java file should exactly be same as the class name inside it for the code to run. So make changes accordingly.