wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Help On Characters! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Help On Characters!" Watch "Help On Characters!" New topic
Author

Help On Characters!

Ankit Up
Greenhorn

Joined: Jun 13, 2009
Posts: 4
Guys,

I am stuck on to characters.
I want to ask you guys that if characters are stored in ASCII format in Java or Unicode because i read that Java follows Unicode and bcause of that it has 16 bits for character.
Also when i do operation like x = x * y where x and y are chars why do i have to cast it.

Another question is why do we append L,D,F at the end of long double and float.

I am Just Starting java.I hope you guys will explain it to me properly

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19680
    
  18

Ankit Up wrote:I am stuck on to characters.
I want to ask you guys that if characters are stored in ASCII format in Java or Unicode because i read that Java follows Unicode and bcause of that it has 16 bits for character.

You read correctly. Each char takes up 2 bytes - or 16 bits.

Also when i do operation like x = x * y where x and y are chars why do i have to cast it.

The result of each mathematical expression is the highest type of its operands (e.g. long + int == long), but never smaller than int. That means that any mathematical expression will never result in a byte, short or char value. That's why x * y is int and you need to cast it back to char.

Another question is why do we append L,D,F at the end of long double and float.

Any whole number is implicitly an integer. By appending L (never use lowercase l, it looks too much like 1) you explicitly turn it into a long.
Any fractional number is implicitly a double. You can append F or f to make it a float instead, or D or d to make it explicit that it is a double.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help On Characters!