Java Programming

ASCII in Java

 

ASCII ( American Standard Code for Information Interchange)  is a character encoding standard used in computers and communication equipment to represent text, control characters, and other data. ASCII was first developed in the 1960s and has been widely used since then.

The ASCII standard uses a 7-bit binary code to represent each character, allowing for a total of 128 different characters. These characters include basic Latin letters (both uppercase and lowercase), digits, punctuation marks, special symbols, and control characters. The original ASCII standard defines characters from 0 to 127, with each value representing a specific character.

For example:

  • The ASCII code for the letter ‘A’ is 65 (01000001 in binary).
  • The ASCII code for the letter ‘a’ is 97 (01100001 in binary).
  • The ASCII code for the digit ‘0’ is 48 (00110000 in binary).
  • The ASCII code for the exclamation(!)is 33 (00100001 in binary).

Since 7 bits provide only 128 possible values, ASCII has limitations for representing characters from languages with more characters, like Chinese, Japanese, or Cyrillic. As a result, various extended versions of ASCII, such as UTF-8 (Unicode Transformation Format 8-bit) and UTF-16, were developed to support a broader range of characters and cover multiple languages.

UTF-8 is currently the most widely used character encoding, as it is backward compatible with ASCII, meaning that the first 128 characters of UTF-8 are identical to ASCII, allowing ASCII-based software and systems to process UTF-8 encoded text without any issues.

Java Program to print the ASCII value

Example…

class ascii

{

public static void main(String aa[])

{

char ch;

int x=30;

do

{

ch=(char)x;

System.out.print(ch+” “);

if(x%25==0)

System.out.println();

x++;

}

while(x<=255);

}

}

ASCII Values in java(ASCII Table)

Explanation…

In this example, we use a do-while loop….

The working of the do-while loop is the same as the while loop except for the fact that the condition is checked at the end of the loop. So the do-while loop is also called the Exit Controlled loop. The effect of this checking is that even if the condition is not fulfilled, the statements in the body of the loop will be executed at least once. So the minimum number of times a do-while loop runs is 1.

In the while loop, the test condition is checked at the beginning of the loop, but in the do-while, the test condition is checked at the end of the loop.

Recommended Posts

C++ Programming

Visibility modes in C++

In C++, visibility modes refer to the accessibility of class members (such as variables and functions) from different parts of a program. C++ provides three visibility modes: public, private, and protected. These modes control the access levels of class members concerning the outside world and derived classes. Public: Members declared as public are accessible from […]

Rekha Setia 
C++ Programming

Inheritance in C++

In C++, inheritance is a fundamental concept of object-oriented programming (OOP) that allows you to create a new class based on an existing class, known as the base or parent class. The new class is called the derived or child class. Inheritance facilitates code reuse and supports the creation of a hierarchy of classes. There […]

Rekha Setia 
C++ Programming

C++ Classes and Objects

In C++, classes and objects are fundamental concepts that support object-oriented programming (OOP). Here’s a brief overview of classes and objects in C++: Classes: In C++, a class is a user-defined data type that allows you to encapsulate data members and member functions into a single unit. Classes are the building blocks of object-oriented programming […]

Rekha Setia 

Leave A Comment