char keyword in Java

The “char” keyword is used to declare a variable of character type.

char” is a Java primitive type.

A char variable can store a single Unicode character.

For example:

char delimiter = ';';

char letterA = 'A';

char letterB = 'B';

char letterC = 'C';

The char keyword can be used as a method parameter

  1. public void displayLetter(char letter) {
  2.  
  3.     System.out.println("passed letter is "+letter);
  4.  
  5. }
public void displayLetter(char letter) {

    System.out.println("passed letter is "+letter);

}


The char keyword can be used as a return type of a method as well

  1. public char getLetter() {
  2.  
  3.     return 'A';
  4.  
  5. }
public char getLetter() {

    return 'A';

}


The Character class includes useful static methods for dealing with char variables, including isDigit(),isLetter(), isWhitespace() and toUpperCase().

About the Author

Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on