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 primitive char and unicode value assignments 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 "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
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3268
    
  52

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 ExamLab - a free SCJP / OCPJP exam simulator
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Kamil Wojcik
Ranch Hand

Joined: May 19, 2008
Posts: 78

Abimaran, You can try also something like this


SCJP 6.0 Passed | SCWCD Passed | PSM 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
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3268
    
  52

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

Joined: Aug 16, 2005
Posts: 14435
    
  23

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 8 API documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: primitive char and unicode value assignments