Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why char data of two bytes.

 
Ritesh raushan
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why sun microsystem given a character has a 2bytes capacity.
 
Stephan van Hulst
Bartender
Pie
Posts: 6113
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many bytes would you use?
 
Ritesh raushan
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stephan van Hulst wrote:How many bytes would you use?



char takes one byte for each character then why he given char as a 2 bytes.
 
Winston Gutkowski
Bartender
Pie
Posts: 10504
64
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ritesh raushan wrote:char takes one byte for each character...

Says who? You've plainly discovered that in Java, it doesn't.

Winston
 
Stephan van Hulst
Bartender
Pie
Posts: 6113
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a character was only one byte, you could have no more than 256 characters. The latin alphabet alone uses 24 letters and 10 digits. What about all the other languages with their alphabets and special letters and symbols? There is no way you can represent them all with only one byte.

With two bytes, you can represent 65.536 characters. This seems much more adequate.
 
Ritesh raushan
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks stephen.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic