| 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
|
|
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
|
|
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
|
|
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
|
 |
 |
|
|
subject: primitive char and unicode value assignments
|
|
|