Identifying Ignorable Java Characters

JavaJavaBeginner
Practice Now

Introduction

The isIdentifierIgnorable(char ch) method is a part of the Character class in Java. This method is used to check whether a specific character can be considered as an ignorable character in Java or a Unicode identifier or not.


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/comments("`Comments`") 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/variables("`Variables`") java/SystemandDataProcessingGroup -.-> java/system_methods("`System Methods`") subgraph Lab Skills java/scope -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/classes_objects -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/class_methods -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/modifiers -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/oop -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/packages_api -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/user_input -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/wrapper_classes -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/identifier -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/arrays -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/comments -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/data_types -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/operators -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/output -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/strings -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/variables -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} java/system_methods -.-> lab-117517{{"`Identifying Ignorable Java Characters`"}} end

Declare the main method

Declare the main method, which is the entry point of the Java program, as shown below:

public static void main(String[] args) {
    // your code here
}

Create some variables

Create some variables with different characters, as shown below:

char ch1 = '\u0000'; // ASCII null character
char ch2 = '\u001F'; // ASCII unit separator character
char ch3 = '\u007F'; // ASCII delete character
char ch4 = 'a';      // a normal character

Check if characters are identifier ignorable

Using the Character.isIdentifierIgnorable(char ch) method, print whether each character is an ignorable character in Java or Unicode identifier.

System.out.println("Is " + ch1 + " ignorable? " + Character.isIdentifierIgnorable(ch1));
System.out.println("Is " + ch2 + " ignorable? " + Character.isIdentifierIgnorable(ch2));
System.out.println("Is " + ch3 + " ignorable? " + Character.isIdentifierIgnorable(ch3));
System.out.println("Is " + ch4 + " ignorable? " + Character.isIdentifierIgnorable(ch4));

Here is the complete code for your reference:

public class IdentifierIgnorable {
    public static void main(String[] args) {
        char ch1 = '\u0000'; // ASCII null character
        char ch2 = '\u001F'; // ASCII unit separator character
        char ch3 = '\u007F'; // ASCII delete character
        char ch4 = 'a';      // a normal character

        System.out.println("Is " + ch1 + " ignorable? " + Character.isIdentifierIgnorable(ch1));
        System.out.println("Is " + ch2 + " ignorable? " + Character.isIdentifierIgnorable(ch2));
        System.out.println("Is " + ch3 + " ignorable? " + Character.isIdentifierIgnorable(ch3));
        System.out.println("Is " + ch4 + " ignorable? " + Character.isIdentifierIgnorable(ch4));
    }
}

Compile and run the Java program

Compile the Java program using the following command in the terminal:

javac ~/project/IdentifierIgnorable.java

Run the Java program using the following command:

java IdentifierIgnorable

Test the program

The program will output the result of whether each character is an ignorable character in Java or Unicode identifier.

Is ignorable? true
Is ignorable? true
Is ignorable? true
Is a ignorable? false

You can test the program with different characters and check their output.

Modify the program

Try modifying the program to take input from the user and check if the character is an ignorable character in Java or a Unicode identifier. Here is the modified code:

import java.util.Scanner;

public class IdentifierIgnorable {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        System.out.print("Enter a character: ");
        char ch = input.next().charAt(0);

        System.out.println("Is " + ch + " ignorable? " + Character.isIdentifierIgnorable(ch));
    }
}

Compile and run the modified program

Compile the modified Java program using the following command in the terminal:

javac ~/project/IdentifierIgnorable.java

Run the modified Java program using the following command:

java IdentifierIgnorable

Test the modified program

The program will ask for a character as input and output whether it is an ignorable character in Java or Unicode identifier.

Enter a character:
$
Is $ ignorable? false

Summary

In this lab, you have learned:

  • The Java isIdentifierIgnorable(char ch) method is used to check whether a character can be considered as an ignorable character in Java or a Unicode identifier.
  • ISO control characters that are not whitespace, and all characters that have the FORMAT general category value, are considered as ignorable characters or Unicode identifier.
  • How to use this method to check whether a character is an ignorable character in Java or Unicode identifier.

Other Java Tutorials you may like