Define a Class
Define a class CharGetName
and implement the main()
method. In the main()
method, we will perform the operation of getting the Unicode name of different characters like "H", "f", etc in Java.
Full code looks like below-
import java.lang.Character;
public class CharGetName {
public static void main(String[] args) {
int codepoint1 = 72; // H
int codepoint2 = 102; // f
int codepoint3 = 0;
String name1 = Character.getName(codepoint1);
String name2 = Character.getName(codepoint2);
String name3 = Character.getName(codepoint3);
System.out.println("The name of character " + Character.toChars(codepoint1)[0] + " is "+name1);
System.out.println("The name of character " + Character.toChars(codepoint2)[0] + " is "+name2);
System.out.println("The name of character with codepoint 0 is "+ name3);
}
}
In this step, we have defined a class named CharGetName
with the main method inside it. In the main method, we have created an integer variable with the Unicode code point of characters as its values: codepoint1
having a value of 72
(H) and codepoint2
having a value of 102
(f). We have used the Character.getName()
method to get the names of the characters and then we have printed the name of the characters using System.out.println()
method.