File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes I don't get it! 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 "I don Watch "I don New topic
Author

I don't get it!

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

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
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
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

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
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
LOL ... Peter, are you REALLY bored today Hope you had a character to Unicode translator to create the file


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Java Nut and satya5
please read the JavaRanch Naming Policy and register again with names complying with the policy.
Thank you for your cooperation

------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform


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

Joined: Nov 04, 2001
Posts: 16
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
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

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: 9043
    
  10
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I don't get it!
 
Similar Threads
explanation of answers
about forward refrencing
Private/Protected interfaces
need your help about a access qeustion.
SCJP doubt