Signup/Sign In

Java Character isJavaIdentifierPart(int codePoint) Method

Java isJavaIdentifierPart(int codePoint) is a part of Character class. This method is used to determine whether the specified Unicode codepoint character is a part of a Java identifier or not.

It must be noted that this method does not handle supplementary characters. A Unicode character is a part of Java identifier if any of the following conditions are satisfied:

  • it is a letter
  • it is a currency symbol (such as '$')
  • it is a connecting punctuation character (such as '_')
  • it is a digit
  • it is a numeric letter (such as a Roman numeral character)
  • it is a combining mark
  • it is a non-spacing mark
  • isIdentifierIgnorable returns true for the character.

Syntax:

public static boolean isJavaIdentifierPart(int codePoint)

Parameters:

The parameter passed is the Unicode codepoint character to be checked for Java identifier.

Returns:

Returns the boolean value true if the specified Unicode character is a part of Java identifier else returns false.

Example 1:

Here, the characters are checked whether they are a part of a Java identifier or not.

public class StudyTonight
{  
	public static void main(String[] args)
	{  
		int cp1 = 48;  
		int cp2 = 61;  
		int cp3 = 119;  
		int cp4 = 90;   
		int cp5 = 1232;  

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

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


0 is a part of Java identifier??: true
= is a part of Java identifier??: false
w is a part of Java identifier??: true
Z is a part of Java identifier??: true
? is a part of Java identifier??: 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: ");  
			Scanner sc = new Scanner(System.in);         
			int cp = sc.nextInt();  
			boolean b = Character.isJavaIdentifierPart(cp);
			System.out.println((char)cp + " is a part of Java identifier??: "+b);
		}
		catch(Exception e)
		{
			System.out.println("Invalid Input!!");
		}
	}  
}


Enter the Unicode codepoint: 77
M is a part of Java identifier??: true
******************************************
Enter the Unicode codepoint: 44
, is a part of Java identifier??: false

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.