It's not a secret anymore!
The moose likes Beginning Java and the fly likes chars Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "chars" Watch "chars" New topic


Rajiv Chelsea
Ranch Hand

Joined: Jun 15, 2010
Posts: 88

How is it possible to assign 65 to ch which is a char?
As i know char values shuld be enclosed in single quotes
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15094

Because char is really a numeric type, that can contain values between 0 and 65535.

The 65 is an integer literal, but according to the Java specification it can be assigned to a char using a narrowing primitive conversion if the number fits in the char.

The Unicode code point for the capital letter A is 65.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

oh..the 'char' type is unsigned in java,is it??

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46412
It's all in the Java™ Language Specification; look for char, and it tells you whether it is signed or unsigned.
I agree. Here's the link:
subject: chars
It's not a secret anymore!