java.lang.Character isJavaIdentifierStart(char ch)

Description

The Character.isJavaIdentifierStart(char ch) java method determines if the specified character is permissible as the first character in a Java identifier.

A character may start a Java identifier if and only if one of the following conditions is true:

  • isLetter(ch) returns true
  • getType(ch) returns LETTER_NUMBER
  • ch is a currency symbol (such as ‘$’)
  • ch is a connecting punctuation character (such as ‘_’).

This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the isJavaIdentifierStart(int) method.

The isJavaIdentifierStart(char ch) method of Character class is static thus it should be accessed statically which means the we would be calling this method in this format:

Character.isJavaIdentifierStart(char ch)

Non static method is usually called by just declaring method_name(argument) however in this case since the method is static, it should be called by appending the class name as suffix. We will be encountering a compilation problem if we call the java isJavaIdentifierStart() method non statically.

Method Syntax

public static boolean isJavaIdentifierStart(char ch)

Method Argument

Data Type Parameter Description
char ch the character to be tested.

Method Returns

The isJavaIdentifierStart(char ch) method of Character class returns true if the character may start a Java identifier; false otherwise.

Compatibility

Requires Java 1.1 and up

Java Character isJavaIdentifierStart(char ch) Example

Below is a simple java example on the usage of isJavaIdentifierStart(char ch) method of Character class.

package com.javatutorialhq.java.examples;

import java.util.Scanner;

/*
 * This example source code demonstrates the use of 
 * isJavaIdentifierStart(char ch) method of Character class.
 */

public class CharacterIsJavaIdentifierStartCharExample {

	public static void main(String[] args) {

		// Ask for user input
		System.out.print("Enter a character:");

		// use scanner to get the user input
		Scanner s = new Scanner(System.in);

		// get a single character
		char value = s.nextLine().toCharArray()[0];

		// close the scanner object
		s.close();

		/*
		 * check if the user input is permissible as 
		 * the first character in a Java identifier
		 */

		boolean checkBool = Character.isJavaIdentifierStart(value);
		// print result
		if (checkBool) {
			System.out.print("User input '" + value + "' is permissible as "
					+ "the first character in a Java identifier");
		} else {
			System.out.print("User input '" + value + "' is not permissible as "
					+ "the first character in a Java identifier");
		}

	}

}

Sample Output

Below is the sample output when you run the above example.

java Character isJavaIdentifierPart(int codePoint) example output