Signup/Sign In
LAST UPDATED: NOVEMBER 6, 2020

Java Character isDefined(int codepoint) Method

Java isDefined(int codepoint) method is a part of Character class. This method is used to check whether the specified Unicode codepoint character is defined in Unicode or not. For a codepoint character to be defined in Unicode, a character must satisfy either of the two(or both) conditions:

  • The Character must have an entry in the UnicodeData file.
  • The value of Character is in a range defined by the UnicodeData file.

Syntax:

public static boolean isDefined(int codePoint)  

Parameter:

The parameter passed is the Unicode codepoint character value to be checked whether it is defined in Unicode or not.

Returns:

Returns the boolean value true if the specified codepoint character is defined in Unicode else return false.

Example 1:

Here, the characters are checked by using the isDefined() method whether they are defined in Unicode or not.

public class StudyTonight
{  
	public static void main(String[] args)
	{  
		int cp1 = 66;  
		int cp2 = 78;  
		int cp3 = 101;  
		int cp4 = 90;   
		int cp5 = 121;  

		boolean b1 = Character.isDefined(cp1);  
		boolean b2 = Character.isDefined(cp2);  
		boolean b3 = Character.isDefined(cp3);  
		boolean b4 = Character.isDefined(cp4);  
		boolean b5 = Character.isDefined(cp5);  

		System.out.println((char)cp1 +" is defined?? :  "+b1);  
		System.out.println((char)cp2 +" is defined?? :  "+b2);   
		System.out.println((char)cp3 +" is defined?? :  "+b3);   
		System.out.println((char)cp4 +" is defined?? :  "+b4);   
		System.out.println((char)cp5 +" is defined?? :  "+b5);   
	}  
}  


B is defined?? : true
N is defined?? : true
e is defined?? : true
Z is defined?? : true
y is defined?? : true

Example 2:

Here is a user-defined example where anyone using this code can put a value of his choice and get the equivalent output.

import java.util.Scanner; 
public class StudyTonight
{  
	public static void main(String[] args)
	{  
		try
		{
			System.out.print("Enter the unicode codepoint value: ");  
			Scanner sc = new Scanner(System.in);         
			int cp = sc.nextInt();  
			boolean b = Character.isDefined(cp);
			System.out.println((char)cp + " is defined?? : "+b);
		}
		catch(Exception e)
		{
			System.out.println("Invalid Input!!");
		}
	}  
}  


Enter the unicode codepoint value: 88
X is defined?? : true
*********************************************
Enter the unicode codepoint value: 121
y is defined?? : true

Live Example:

Here, you can test the live code example. You can execute the example for different values, even can edit and write your examples to test the Java code.



About the author:
A Computer Science and Engineering Graduate(2016-2020) from JSSATE Noida. JAVA is Love. Sincerely Followed Sachin Tendulkar as a child, M S Dhoni as a teenager, and Virat Kohli as an adult.