HomeJava

Java for Testers – char data type

Java for Testers – char data type

<<Previous Post                    << Complete Tutorial>>                        Next Post>>

In the previous article, I have explained about double data type.

In this article, I am going to explain and practically demonstrate char data type.

Java for Testers – char data type

Single Character values like ‘s’ etc. can be stored into a variable which is declared with char data type.

For example:

In the above example, we have declared the variable c with char data type, and hence we are able to store the character values like ‘s’ into the variable.

Follow the below steps for practically implementing char data type in Java:

1) Let’s create a Java program and create a Demo class as shown below:

Note: If you are not aware of creating a Java project and a Class in Java, refer to our previous article – Creating a Java project in Eclipse IDE

Print statements - Java project

2) Inside the main() method, let’s create a variable, declare the variable with char data type and assign the variable with a character value ‘s’ as shown below:

Note: The single-letter character should be enclosed with single quotes to store into the char declared variable as shown below:

Using Data Types Java - char

3) Now print the value stored in the variable by printing the variable using the print statement as shown below:

Using Data Types Java - char printed

4) Save the Project and click on the ‘Run’ button.

Observe that the Program got executed and the character value ‘s’ stored in the variable c got printed as shown below:

Using Data Types Java - print char

Copy the above-explained code from the below section:


Before concluding this article, I would like to give more details about the char data type in Java.

The char data type is a single 16-bit Unicode character.

As Java uses Unicode system to represent a character, it is capable of representing almost all the characters of the world’s written languages.

Here concludes this article.

In the next article, I will explain and demonstrate the boolean data type in Java.

Next Steps:

  • > To learn more about Java, continue to the next post (Click on Next Post link below)
  • > Check complete Java Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below:

Happy Learning 🙂

Arun Motoori (www.QAFox.com)

On a mission to help the Testing Community in all possible ways.

<<Previous Post                    << Complete Tutorial>>                        Next Post>>

If you like this article, share it on LinkedIn using the below button:

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *