This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, in my study notes I have the following: 1) System.out.println(4 + '' + 2); prints 38. Binary numbers promotion rule. Java will promote each operand of a binary operator to it's widest type. Java promotes the character literal('') to it's Unicode value 32. 2) 'b'+ 63; compiles correctly, promoting char to int. 98 giving 161. All operands of type byte, char, short are promoted to at least int before mathematical operations are performed. If one of the operands is larger than an int, then the other is promoted to the same type. My question is why is the char literal in note 1 ('')given an int value of 32(I suppose) and the char in note 2 ('b') promoted to int value 98 Thanks :confused
Mike JAva uses unicode to represent its tokens internally. From the JLS section 3.1 'The first 128 characters of the Unicode character encoding are the ASCII characters.' For a good reference of the ASCII characters and their values check out this page. hope that helps
Joined: Jul 18, 2001
AhhHah! Thanks for the links. But Dave, how the heck is a fella supposed to know that? Experience I guess. Geez.
Joined: May 10, 2001
Originally posted by Mike Kelly: ...how the heck is a fella supposed to know that?