Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

character unicode values

 
kathir vel
Ranch Hand
Posts: 92
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
In this pgm they are using unicode values.Should I know all unicodes for all characters for SCJP exam?

01: public static void main(String[] args){
02: char c = '\u0042';
03: switch(c) {
04: default:
05: System.out.println("Default");
06: case 'A':
07: System.out.println("A");
08: case 'B':
09: System.out.println("B");
10: case 'C':
11: System.out.println("C");
12: }
13: }
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kathir vel:
... Should I know all unicodes for all characters for SCJP exam?...

No. I think this question is just illustrating that a char literal can be expressed as a Unicode value and a char is int convertible (so it can be used in a switch/case). You should know the correct format for a Unicode char literal (for example, '\u0042'), but you do not need to know how the values translate.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think this is actually on the exam, but here's a detail to keep in mind. Unicode carriage returns ('\u000d') and line feeds ('\u000a') are not valid Java literals. The reason is that Unicode values are translated very early by the compiler, so instead of a char literal, it's as if you had an actual carriage return or line feed in your code.

(See 3.10.4 Character Literals and 3.4 Line Terminators.)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic