• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I don't get it!

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
LOL ... Peter, are you REALLY bored today Hope you had a character to Unicode translator to create the file
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right Pervez... I always forget to look at those d%^$ dates
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Pervez Amin
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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).]
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the same question regarding maha anna asked here (and the answer).
[This message has been edited by Marilyn deQueiroz (edited November 23, 2001).]
reply
    Bookmark Topic Watch Topic
  • New Topic