| Author |
Java Character Declaration Format
|
sur manickam
Greenhorn
Joined: Dec 27, 2008
Posts: 6
|
|
|
When we declare and store a character in Java, in which format the character is stored internally ascii or unicode or utf8?
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
A char is stored in two bytes, and stores the unicode value. You can confirm this with the following code:
Output:
61
1234
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
sur manickam
Greenhorn
Joined: Dec 27, 2008
Posts: 6
|
|
|
Thank you Rob
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32651
|
|
|
As Rob has told you, it is a 16-bit unsigned integer (whole number).
|
 |
sur manickam
Greenhorn
Joined: Dec 27, 2008
Posts: 6
|
|
|
Out of 16 bits, how many bits are needed to store one character ?
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12911
|
|
|
16 bits.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Not necessarily. Only 8 are needed for ASCII characters. However, all 16 are reserved for all characters, regardless of how many are needed.
|
 |
sur manickam
Greenhorn
Joined: Dec 27, 2008
Posts: 6
|
|
|
Thank you Rob. I also agree with you. Out of 16 bits 8 bits are needed for ascii. So in the remaining 8 bits, is it possible to add some other 8 bits? If so, how to do it?
|
 |
Darryl Burke
Bartender
Joined: May 03, 2008
Posts: 4163
|
|
Hmm...
http://forums.sun.com/thread.jspa?threadID=5357602
|
luck, db
There are no new questions, but there may be new answers.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
The other 8 bits are 0, and if you want it to be the same character you should keep them 0.
If you want to merge two ASCII characters into one char variable that will create a completely different character. In other words, don't do that.
|
 |
 |
|
|
subject: Java Character Declaration Format
|
|
|