Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help On Characters!

 
Ankit Up
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20546
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic