Open In App

How does Java process the backspace terminal control character?

Improve
Improve
Like Article
Like
Save
Share
Report

What is the backspace terminal control character?

In this article, we will discuss about the backspace terminal control character. It is used to move the cursor one character back. For backspace terminal control we use ‘\b’ notation in Java.

What does the backspace terminal control character do?

By using backspace terminal control we remove the character which is before the ‘\b’ notation in a string. 

But there is only one condition: When we put the ‘\b’ notation in the string, we have to take care if there is something after the ‘\b’ notation. If this condition is not satisfied it runs with the same string which is provided in the input without any change.

How does Java process the backspace terminal control character?

Java doesn’t handle that ‘\b’ character at all. All it knows about is a byte stream onto which the operating system says it can write bytes and it will do so including an ASCII backspace. when the stream/string receives that character, has nothing whatsoever to do with Java. It is totally terminal dependent. Some terminals will erase the previous character, some will display the backspace character as some weird symbol.

For better understanding follow below simple code example:

Java




// Java code to explain the use of '\b'
  
import java.io.*;
  
class GFG {
    public static void main(String[] args)
    {
        // Declare the backspace terminal notation
        char bc = '\b';
        System.out.print("Hellooo" + bc + "GeeksFor\bGeeks");
    }
}


Output

HelloooGeeksForGeeks

Conclusion:

See here the terminal is showing some weird symbol instead of erasing the previous character. So, we can conclude that though this backspace control is useful for some cases when we want to erase a particular character in the stream/ string, the only flaw is that Java does not handle it and due to this reason some compilers or interpreters show weird symbols.


Last Updated : 26 Oct, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads