Character Data type in Java | Core Java Tutorials

This Core Java Tutorials  “Character Data type in java” explains clearly about how to store character into memory and why character occupies 2 bytes memory and what is the difference between ASCII and UNICODE character systems.


Why char data type limits discussion in integers?

  • We cannot store a symbol directly into memory.
  • Computer stores data in binary format.
  • Character cannot be converted into Binary.
  • We use integers to represent symbols called character system.
  • Hence we can store integer corresponding binary value in place of symbol.

 

How can we store a symbol into 1 byte memory in C or C++?

  • A language at most having 256 symbols(1 byte range)
  • According to ASCII character system any symbol in any language is assigned with value within range of 0 to 255.
  • Hence we can store the symbol corresponding value in 1 byte memory.

ASCII Representation

 

What is character system?

  • A character system represents all the symbols of one language using constant integer values.
  • For example ASCII.

 

Why character occupy 2 bytes memory in java and .net where as it occupies only 1 byte in C and C++?

  • Java & .net apps are web apps.
  • Web app need to represent more than one language character set a time.
  • Hence it occupies 2 bytes.
  • C & C++ are platform dependent. These can represent only one language at a time.

 

The best example that describes any language in this world is having not more than 256 symbols is keyboard.

Share this