From the before mentioned Java Quiz Pages http://www.angelfire.com/or/abhilash/Main.html Why does this not compile public class AQuestion { //char a = '\u000A'; } And this does: public class AQuestion { //char a = '\u0001'; } Note that the code in question is commented out in both instances, but the compiler parses this code and checks syntax anyway! Anyone know why?
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Java Nut: While I donot know the exact reason for this kind of behavior, (if this is holding up your work , i hope you take this comment in a lighter sense ), you could work around the problem using /* char a = '\u000A'; */ which works. Regds. - satya
Ajith Kallambella
Sheriff
Joined: Mar 17, 2000
Posts: 5782
posted
0
For some reason the compiler is not liking the char declaration within the // comments If you change it to an int, or any other damn thing, it works fine. Gods must be crazy.
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
maha anna
Ranch Hand
Joined: Jan 31, 2000
Posts: 1467
posted
0
Java Nut, The compiler acts according to the Java lang spec. From JLS -------- Because Unicode escapes are processed very early, it is not correct to write '\u000a' for a character literal whose value is linefeed (LF); the Unicode escape \u000a is transformed into an actual linefeed in translation step 1 (�3.3) and the linefeed becomes a LineTerminator in step 2 (�3.4), and so the character literal is not valid in step 3. Instead, one should use the escape sequence '\n' (�3.10.6). Similarly, it is not correct to write '\u000d' for a character literal whose value is carriage return (CR). Instead, use '\r'. Please refer to JLS especially this section regds maha anna.
Prasad Shanbhag
Greenhorn
Joined: Nov 23, 2001
Posts: 1
posted
0
Why does this not compile public class AQuestion { //char a = '\u000A'; } And this does: public class AQuestion { //char a = '\u0001'; }
Go to the basics.. When ever there is any character in a unicode format like(\uxxxx) then the character is transformed to a real unicode character by the compiler before compilation. So your code before compilation will look like this public class AQuestion { //char a = ' '; } because \u000A is a carraige return(\r). Similarly you cannot use \u000D as that represents a new line character(\n) I hope this should clear your doubt regards Prasad S
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
posted
0
Save the following as Unicode.java (in the default package), compile and run it. Don't worry if you paste the code and it all ends up on one line. Really. Try it. It compiles! Then try to explain what it does Bonus points if you can figure out why it compiles in the first place. Don't worry, you won't get this kind of question at the exam - Peter [This message has been edited by Peter den Haan (edited November 23, 2001).]
Jane Griscti
Ranch Hand
Joined: Aug 30, 2000
Posts: 3141
posted
0
LOL ... Peter, are you REALLY bored today Hope you had a character to Unicode translator to create the file
If you look at the dates you'll see that Java Nut et. al. registered almost 18 months ago!!! I don't think they had a naming convention at JavaRanch in them days!!!. BTW, what ever happened to Maha Anna??
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
posted
0
Right Pervez... I always forget to look at those d%^$ dates ------------------ Valentin Crettaz Sun Certified Programmer for Java 2 Platform
Pervez Amin
Greenhorn
Joined: Nov 04, 2001
Posts: 16
posted
0
What ever happened to Maha Anna?? She's one person who I believe should have a book deal. She had a real gift for explaining complex ideas - she had a real clarity of thought and the ability to make complex ideas seem easy. [This message has been edited by Pervez Amin (edited November 23, 2001).]
Marilyn de Queiroz
Sheriff
Joined: Jul 22, 2000
Posts: 9033
10
posted
0
See the same question regarding maha anna asked here (and the answer). [This message has been edited by Marilyn deQueiroz (edited November 23, 2001).]
JavaBeginnersFaq "Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt