The second example is clearly superior. The meaning of the second example is immediately obvious when you look at the code. The meaning of the first example is only obvious if you have memorized the entire ASCII table in your head.
You should distinguish between checking for a specific character, or checking for a range or class of characters.
1) Checking for a specific character.
For ordinary characters, use the character literal, e.g., if(ch=='z')...
. If you check against special characters like tab or line break, you should use the escapes, like if (ch=='\n')...
. If the character you are checking for is unusual (e.g not immediately recognizable or not available on a standard keyboard), you might use a hex character code rather than the literal character. But since a hex code is a "magic value", you would extract it to a constant and document it:
const char snowman = 0x2603; // snowman char used to detect encoding issues
...
if (ch==showman)...
Hex codes is the standard way of specifying character codes.
2) Checking for a character class or range
You really shouldn't be doing this directly in application code, but should encapsulate it in a separate class only concerned with character classification. And you should be vary of this, since libraries already exists for this purpose, and character classification is usually more complex than you think, at least if you consider characters outside the ASCII-range.
If you are only concerned about characters in the ASCII range, you could use character literals in this library, otherwise you would probably use hex-literals. If you look at the source code for the the Java builtin character library, it also refers to character values and ranges using hexadecimal, since this is how they are specified in the Unicode standard.
VK_
constants your supposed to use, secondly using char codes is better than char Java is a type safe language your not supposed to do cross-type checking. @Brandin It's called coding practicesVK_*
constants correspond to keys not characters.