• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

character unicode values

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: }
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
Do you want ants? Because that's how you get ants. And a tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic