aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Valid Declarations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Valid Declarations" Watch "Valid Declarations" New topic
Author

Valid Declarations

Steve Ram
Greenhorn

Joined: Jun 16, 2003
Posts: 2
Hi,
Got this question from Mughal/Rasmussen:-
Which of the following lines are valid declarations? Select all valid answers
a) char a = '\u0061';
b) char \u0061 = 'a';
c) ch\u0061r a = 'a';
The answer says everything is valid.
I can understand the logic behind the answer...you can replace any char with unicode equivalent..but i tried it in SunOne IDE and the compilation fails.
Am i doing anything wrong?
Thanks
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
studentforever,
Welcome to Javaranch, a friendly place for Java greenhorns
You can find the answer to this question in the following discussion:
http://www.coderanch.com/t/240779/java-programmer-SCJP/certification/ch-valid
Moreover, we ain't got many rules 'round these parts, but we do got one. Please change your displayed name to comply with the JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Steve Ram
Greenhorn

Joined: Jun 16, 2003
Posts: 2
Thanks Valentin and sorry about the name.
I still am not sure how to compile it.. Is there anything i should be importing or setting to tell the compiler i am using unicode char?
Thanks in advance.
James Chegwidden
Author
Ranch Hand

Joined: Oct 06, 2002
Posts: 201
I did a test program with the problem p. 33.
The answer is correct
Did you type in each line separately and compile it?
If you type in all lines together it will try to redefine the literal which you can not do.
Got It?
Also, did you notice earlier in text about how Unicode is declared so
char a = '\u0061' - p25. Character literal valid
char \u0061 = 'a' - yep valid rewrite:
char a = 'u0061' just replaced
value - correct
ch\u0061r a = 'a' - think \u0061 is an a right?
So char a = 'a' - just replace the values.
Understand the meaning of a literal and the assignment operator
[ June 17, 2003: Message edited by: James Chegwidden ]

Author and Instructor, my book
Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
I tried ,compilation was fine.But I didn't understand the logic fully.does JVM replaces unicode value with the equivalent unicode character during runtime?
Thanks
Veena


SCJP1.4
"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
It is the compiler who translates Unicode escapes to Unicode characters.
See for JLS 3.2 more.


SCJP2. Please Indent your code using UBB Code
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Valid Declarations
 
Similar Threads
Mughal Question chap3 - q5
what is the difference?
khailds question on char declaration
Unicode
Valid declarations?