Categories: Keyword in Java

The char keyword in Java programming language

The char keyword in Java programming language

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.

Variable declaration

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.

 

Method declaration

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

abstract keyword in Java

boolean Keyword in Java

break keyword in Java

Byte keyword in Java 

case keyword in Java 

catch keyword in Java 

char keyword in Java 

class keyword in Java 

continue keyword in Java 

default keyword in Java 

do keyword in Java

double keyword in Java

else keyword in Java

enum keyword in Java

extends keyword in Java

final keyword in Java

finally keyword in Java

float keyword in Java

for keyword in Java

if keyword in Java

static keyword in Java

super keyword in Java

transient keyword in Java

public keyword in Java

private keyword in Java

protected keyword in Java

 

Suggested for you

Usage of this statement in the Java language

Keywords in Java language

Keywords in C language

Keywords in Python language

 

 

 

 

The static keyword in Java programming language
The class keyword in Java programming language
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

3 hours ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago