Identify Unicode Identifier Parts in Java

JavaJavaBeginner
Practice Now

Introduction

In this lab, you will learn about the isUnicodeIdentifierPart(int codePoint) method of the Character class in Java. This method is used to check whether a specified Unicode character is a part of a Unicode identifier or not. A Unicode identifier is a sequence of characters that is used to uniquely identify an entity in a program.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL java(("`Java`")) -.-> java/ProgrammingTechniquesGroup(["`Programming Techniques`"]) java(("`Java`")) -.-> java/ObjectOrientedandAdvancedConceptsGroup(["`Object-Oriented and Advanced Concepts`"]) java(("`Java`")) -.-> java/BasicSyntaxGroup(["`Basic Syntax`"]) java(("`Java`")) -.-> java/DataStructuresGroup(["`Data Structures`"]) java(("`Java`")) -.-> java/StringManipulationGroup(["`String Manipulation`"]) java(("`Java`")) -.-> java/SystemandDataProcessingGroup(["`System and Data Processing`"]) java/ProgrammingTechniquesGroup -.-> java/scope("`Scope`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/classes_objects("`Classes/Objects`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/class_methods("`Class Methods`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/modifiers("`Modifiers`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/oop("`OOP`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/packages_api("`Packages / API`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/user_input("`User Input`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/wrapper_classes("`Wrapper Classes`") java/BasicSyntaxGroup -.-> java/identifier("`Identifier`") java/DataStructuresGroup -.-> java/arrays("`Arrays`") java/BasicSyntaxGroup -.-> java/data_types("`Data Types`") java/BasicSyntaxGroup -.-> java/operators("`Operators`") java/BasicSyntaxGroup -.-> java/output("`Output`") java/StringManipulationGroup -.-> java/strings("`Strings`") java/BasicSyntaxGroup -.-> java/type_casting("`Type Casting`") java/BasicSyntaxGroup -.-> java/variables("`Variables`") java/SystemandDataProcessingGroup -.-> java/system_methods("`System Methods`") subgraph Lab Skills java/scope -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/classes_objects -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/class_methods -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/modifiers -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/oop -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/packages_api -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/user_input -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/wrapper_classes -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/identifier -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/arrays -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/data_types -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/operators -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/output -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/strings -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/type_casting -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/variables -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} java/system_methods -.-> lab-117561{{"`Identify Unicode Identifier Parts in Java`"}} end

Create a new Java file

Create a new file in the ~/project directory with the name UnicodeIdentifier.java using the following command:

touch ~/project/UnicodeIdentifier.java

Define the main method

In this step, define the main method and import the java.util.Scanner class as shown in the code block below.

import java.util.Scanner;

public class UnicodeIdentifier {

    public static void main(String[] args) {

    }
}

Get the Unicode character from user input

In this step, get the value of a Unicode character from the user input using a Scanner class. Add the below code inside the main method.

    Scanner scanner = new Scanner(System.in);
    System.out.print("Enter a Unicode character: ");
    int unicodeValue = scanner.next().codePointAt(0);

Check if the Unicode character is a part of a Unicode identifier

Use the isUnicodeIdentifierPart(int codePoint) method of the Character class to check if the specified Unicode character is a part of a Unicode identifier or not. Add the below code inside the main method.

    boolean isUnicodeIdentifier = Character.isUnicodeIdentifierPart(unicodeValue);

Print the output

Use the System.out.println() method to print the result to the console. Add the following code inside the main method.

    System.out.println((char) unicodeValue + " is a part of a Unicode identifier: " + isUnicodeIdentifier);

Compile and run the program

Compile the program using the following command:

javac ~/project/UnicodeIdentifier.java

Run the program using the following command:

java UnicodeIdentifier

Summary

In this lab, you have learned how to check if a character is a part of a Unicode identifier using the isUnicodeIdentifierPart(int codePoint) method of the Character class in Java. You have also learned how to get user input and print the output to the console using the Scanner class and System class respectively.

Other Java Tutorials you may like