Character.isJavaIdentifierStart() method in Java
The java.lang.Character.isJavaIdentifierStart(char ch) is an inbuilt method in java which determines if the specified character is permissible as the first character in a Java identifier or not. A character may start as 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 ‘_’).
Note: This method cannot handle supplementary characters. To support all Unicode characters, including supplementary characters, use the isJavaIdentifierStart(int) method.
Syntax:
public static boolean isJavaIdentifierStart(char ch)
Parameters: The function accepts one mandatory parameter ch which specifies the character to be tested.
Return value: This method returns a boolean value. The boolean value is True if the character may start a Java identifier, False otherwise.
Program below demonstrates the Character.isJavaIdentifierStart(char ch) method:
Program 1:
// Java program to demonstrate the // Character.isJavaIdentifierStart() import java.lang.*; public class gfg { public static void main(String[] args) { // create 2 char primitives c1, c2 char c1 = '9', c2 = '-'; // assign isJavaIdentifierStart results of c1, c2 // to boolean primitives bool1, bool2 boolean bool1 = Character.isJavaIdentifierStart(c1); System.out.println(c1 + " may start a Java identifier is : " + bool1); boolean bool2 = Character.isJavaIdentifierStart(c2); System.out.println(c2 + " may start a Java identifier is : " + bool2); } } |
9 may start a Java identifier is : false - may start a Java identifier is : false
Program 2:
// Java program to demonstrate the // Character.isJavaIdentifierStart() import java.lang.*; public class gfg { public static void main(String[] args) { // create 2 char primitives c1, c2 char c1 = '5', c2 = '_'; // assign isJavaIdentifierStart results of c1, c2 // to boolean primitives bool1, bool2 boolean bool1 = Character.isJavaIdentifierStart(c1); System.out.println(c1 + " may start a Java identifier is : " + bool1); boolean bool2 = Character.isJavaIdentifierStart(c2); System.out.println(c2 + " may start a Java identifier is : " + bool2); } } |
5 may start a Java identifier is : false _ may start a Java identifier is : true
Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#isJavaIdentifierStart(char)
Recommended Posts:
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java lang.Long.builtcount() method in Java with Examples
- Java lang.Long.lowestOneBit() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java Clock tickMinutes() method in Java with Examples
- Java.math.BigInteger.modInverse() method in Java
- Java.math.BigInteger.probablePrime() method in Java
- Java 8 | ArrayDeque removeIf() method in Java with Examples
- Java.util.ArrayList.addall() method in Java
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


