wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Java Character Declaration Format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Character Declaration Format" Watch "Java Character Declaration Format" New topic
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: 19651
    
  18

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 - OCEEJBD 6
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: 37936
    
  22
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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: 19651
    
  18

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: 4523
    
    5

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: 19651
    
  18

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Character Declaration Format
 
Similar Threads
RandomAccessFile
Regular Expression Help
Format Doubt.
newline missing in response
escapre character for xml