File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes what is the size of one ASCII character Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "what is the size of one ASCII character" Watch "what is the size of one ASCII character" New topic
Author

what is the size of one ASCII character

saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
In java what is the size of one ASCII character ?


A = HARDWORK B = LUCK/FATE If C=(A+B) then C=SUCCESSFUL IN LIFE else C=FAILURE IN LIFE
SCJP 1.4
John Dell'Oso
Ranch Hand

Joined: Apr 08, 2004
Posts: 130
Prior, to Java 1.5.x, any character is internally represented as a 16-bit Unicode character using the UTF-16 encoding. As of JDK 1.5.x, changes have been made to support the use of surrogate (16-bit) pairs as well.

True "ASCII" characters only require 7 bits.

Regards,
JD
[ August 26, 2006: Message edited by: John Dell'Oso ]
saikrishna cinux
Ranch Hand

Joined: Apr 16, 2005
Posts: 689
there is no premetive type in java which holds 7-bits ?


so it might be 8 bits
coz byte is a primitive which can hold 1 ascii char

am i right
?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Originally posted by saikrishna cinux:

am i right
?


Depends what on Earth your point is, precisely.


[Jess in Action][AskingGoodQuestions]
John Dell'Oso
Ranch Hand

Joined: Apr 08, 2004
Posts: 130
Saikrishna,

I am fully aware that there is no 7-bit primitive data type in Java. To be honest, your question was a bit vague to start with. You asked about the size of an ASCII character in Java, so I assumed you were referring to the char data type. If this is the case then I stand by my original response.

The reference to ASCII characters only requiring 7-bits means that according to the "standard", the ASCII character set only requires 7 bits to fully represent all of these characters. However, internally within Java they are still represented as 16-bits when using the char data type.

In the past, many vendors made use of the high order 8th bit for their own proprietary purposes and this caused more trouble than it was worth - hence the birth of Unicode.

Nowadays, I would tend to avoid using terms such as "ASCII" and "plain text". These are "historical" terms that are biased towards the mapping of characters in the English (Latin) language only.

There is a plethora of information on the net about this subject and here's a link to the Unicode website if you require more information:

Unicode Home Page

Regards,
JD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is the size of one ASCII character