In this tutorial, we will discuss The char keyword in Java programming language
The char is a keyword that is used to declare a variable as a type of character. In Java, a char variable represents a single (only one) character with enclosed single quote marks shown below.
The syntax of char in java
char var1='B'; //char can be created from char literals. char var2=65; //char can be represented by a numeric representation. char var2='\u0042'; //char can be represented by a Unicode escape sequences representation.
The char keyword( variable) can be used to declare the return type of a method shown below.
public char areAriveHere() { //codes return 'X'; }
Example
class CharEx{ public static void main(String args[]){ char ch1='C'; char ch2=70; char ch3='\u0056'; System.out.println(ch1); System.out.println(ch2); System.out.println(ch3); } }
When the above code is compiled and executed, it will produce the following results
C F V
There are other Java language keywords that are similar to this keyword
Usage of this statement in the Java language
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
Java program to check odd or even using recursion In this tutorial, we discuss a…