Signup/Sign In

Java Character isJavaIdentifierStart(char ch) Method

Java isJavaIdentifierStart(char ch) is a part of Character class. This method is used to determine whether the specified character is the first character in a Java identifier or not.

It must be noted that this method does not handle supplementary characters.

Syntax:

public static boolean isJavaIdentifierStart(char ch)

Parameters:

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

Returns:

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

Example 1:

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

public class StudyTonight
{  
	public static void main(String[] args)
	{  
		char ch1 = ':';  
		char ch2 = 'D';  
		char ch3 = '$';  
		char ch4  = '_';   
		char ch5  = '%';  

		boolean b1 = Character.isJavaIdentifierStart(ch1);  
		boolean b2 = Character.isJavaIdentifierStart(ch2);  
		boolean b3 = Character.isJavaIdentifierStart(ch3);  
		boolean b4 = Character.isJavaIdentifierStart(ch4);  
		boolean b5 = Character.isJavaIdentifierStart(ch5);  

		System.out.println(ch1 +" is a part of Java start identifier??:  "+b1);  
		System.out.println(ch2 +" is a part of Java start identifier??:  "+b2);  
		System.out.println(ch3 +" is a part of Java start identifier??:  "+b3);  
		System.out.println(ch4 +" is a part of Java start identifier?? : "+b4);  
		System.out.println(ch5 +" is a part of Java start identifier??:  "+b5);  

	}  
} 


: is a part of Java start identifier??: false
D is a part of Java start identifier??: true
$ is a part of Java start identifier??: true
_ is a part of Java start identifier?? : true
% is a part of Java start identifier??: false

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 character: ");  
			Scanner sc = new Scanner(System.in);         
			char ch = sc.next().charAt(0);  
			boolean b = Character.isJavaIdentifierStart(ch);
			System.out.println(ch + " is a part of Java start identifier??: "+b);
		}
		catch(Exception e)
		{
			System.out.println("Invalid Input!!");
		}
	}  
}


Enter the character: @
@ is a part of Java start identifier??: false
*************************************************
Enter the character: 7
7 is a part of Java start identifier??: false
*************************************************
Enter the character: m
m is a part of Java start identifier??: 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.