• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 996
  • Last Modified:

Java char value assignments


I am porting a Java project which makes some strange assignments of int values in a function.  I have been Googling this for a while but have not figured it out.

The char c is being passed to the setX function which has a single int parameter.  So why has the original coder used a char instead of int?  The 'else' segment seems to assign an invalid unicode character to the char.  I don't know what c = '\210' does (decimal 210 is Ò).

Sorry the code fragment is so terse, there's not a lot of surrounding code to post.
char c;
if (xPos < 100) {
  c = '\210';
else {
  c = '\uFFF8';
// this is the definition of obj.setX
public void setX(int i)

Open in new window

  • 2
  • 2
1 Solution
Java will automatically cast the int value of a character.
Are you sure the int value of '\210' is what you want?
falmonAuthor Commented:
Well - I am trying to work out what the code does so that I can replicate its behavior in AS3.  So I'm not sure that I want the int value of '\210'.  I am still baffled as to why he decided to create a char, assign it odd values, and then pass it into a function which will cast it as int.  The char isn't used elsewhere.

My assumption was that since "char c = '\uFFF8';" will create a single Unicode character (http://www.fileformat.info/info/unicode/char/fff8/index.htm - possibly... it doesn't even seem to be a valid char) his '\210' assignment would perhaps assign a Unicode char by decimal value?

I guess my question is - what values would I expect as the integer argument to setX for each part of the conditional, given the char values set, and is there any clear reason that the original coder decided to use a char in this way?
Forget about the char. Replace it for an int.
'\210' replace it with 136 and '\uFFF8' with 65528.
Those are the int values that are being passed to that function.
Now, your question about why those two values is a whole different issue.
Can't be answered without some more reference about the application.
falmonAuthor Commented:
OK, that's very useful in terms of how the casting works and basically answers the question!!
Never would have expected those int castings coming from a PHP/JS/AS background.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now