- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java - Character getName() Method
Description
The Java Character getName() method will accept a code point as an argument, and return the character name corresponding to this code point, or null if the code point is unassigned.
Here, unassigned code points are characters that are not assigned in the Unicode standard. They belong to the general category Cn in the Unicode specification.
For some code points, the character name will follow the naming scheme mentioned in the Unicode Name Property section in the Unicode specification. For other codepoints, like ideographs, the naming follows a rule that is different from the one in Unicode specification.
Syntax
Following is the syntax of the Java Character getName() method
public static String getName(int codePoint)
Parameters
codePoint − a Unicode code point
Return Value
This method returns the character name of a code point argument, or null if the code point is unassigned.
Getting Name for a CodePoint Example
The following example shows the usage of Java Character getName() method. In this example, we've initialized an int variable with a codepoint and then using getName() method, we've retrieved the name for the code point and result is printed.
package com.tutorialspoint;
public class getNameDemo {
public static void main(String args[]) {
int cp;
String nm;
cp = 0x0123;
nm = Character.getName(cp);
System.out.println("The character name of the code point: " + nm);
}
}
Output
If we compile and run the given program, the output is produced as follows −
The character name of the code point: LATIN SMALL LETTER G WITH CEDILLA
Getting Name for a High surrogate CodePoint Example
The following example shows the usage of Java Character getName() method. In this example, we've initialized an int variable with a surrogate codepoint and then using getName() method, we've retrieved the name for the code point and result is printed.
If the code point argument passed to the method is a surrogate value, the method will return whether the surrogate is a high surrogate or a low surrogate.
package com.tutorialspoint;
public class getName {
public static void main(String args[]) {
int cp;
String nm;
cp = 0xd810;
nm = Character.getName(cp);
System.out.println("The character name of the code point: " + nm);
}
}
Output
If we compile and run the program above, the output is as follows −
The character name of the code point: HIGH SURROGATES D810
Facing Exception while Getting Name for an Invalid CodePoint Example
The following example shows the usage of Java Character getName() method. In this example, we've initialized an int variable with an invalid codepoint and then using getName() method, we've retrieved the name for the code point and result is printed.
If the code point argument passed to the method is not a valid code point, the method will throw an IllegalArgument exception.
public class getName {
public static void main(String args[]) {
int cp;
String nm;
cp = 0x5624690;
nm = Character.getName(cp);
System.out.println("The character name of the code point: " + nm);
}
}
Exception
Once the program is compiled and run, an exception is thrown as follows −
Exception in thread "main" java.lang.IllegalArgumentException: Not a valid Unicode code point: 0x5624690
at java.base/java.lang.Character.getName(Character.java:11612)
at getName.main(getName.java:10)