This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes primitive char and unicode value assignments Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "primitive char and unicode value assignments" Watch "primitive char and unicode value assignments" New topic
Author

primitive char and unicode value assignments

Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066



What is wrong here? I couldn't find out it! Thanks Advanced!



|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2691
    
    3

The character \u000A is something similar to a new line. In other words, your code gives a compile time error because of the same reason of why the following code is wrong:


Author of ExamLab (Download) - the free mock exam kit for SCJP / OCPJP
Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Kamil Wojcik
Ranch Hand

Joined: May 19, 2008
Posts: 77

Abimaran, You can try also something like this


SCJP 6.0 Passed | SCWCD Passed | SCEA in progress... | SCBCD in progress...
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Kamil Wojcik wrote:Abimaran, You can try also something like this


I couldn't understand this! Thanks Devaka Cooray
Devaka Cooray
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2691
    
    3

Abimaran Kugathasan wrote:I couldn't understand this!


Have a look at the commented line. Since \u000A represents a new line, it is equivalent to the following:

Now, the second statement is not commented and thus it gets executed.
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12921
    
    3

The thing to be aware about here is that Unicode escapes such as \u000a are processed as the very first step in the compiler, before the compiler really looks at your code. The Unicode-escaped codes are replaced by their real characters, and \u000a is ofcourse a newline character.

Because of how this works, you cannot use Unicode escapes as a general way to include special characters in your source code (that's not what they are meant for).


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: primitive char and unicode value assignments
 
Similar Threads
Compiler Error in Commented Line. Why ?
range of char
char value assignment
comment
Unicode representation of a character