Determine Java Identifier Start Character

Beginner

Introduction

In this lab, you will learn how to use the Java isJavaIdentifierStart(char ch) method. This method helps to determine whether the specified character is the first character in a Java identifier or not.

Declare the characters to be checked

Declare the characters that need to be checked for Java start identifier using the char data type.

char ch1 = ':';
char ch2 = 'D';
char ch3 = '$';
char ch4  = '_';
char ch5  = '%';

Check if the characters are a part of Java start identifier

Use the Character.isJavaIdentifierStart(char ch) method to check whether the specified characters are a part of Java start identifier.

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);

Print the output for each character

Print the output for each character using System.out.println() method.

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);

Summary

In this lab, you learned how to use the isJavaIdentifierStart(char ch) method of the Java Character class. You learned how to determine whether the specified character is the first character in a Java identifier or not. You also learned how to create a Java file, compile the code using the command line, and run the code.

Other Tutorials you may like