wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Character Literals Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Character Literals" Watch "Character Literals" New topic

Character Literals

Sandip Kaviman
Ranch Hand

Joined: Apr 27, 2004
Posts: 49
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'.

char c='\u000a'; gives compilation error while char c='\u000d'; does not?

Any explanation?
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

The paragraph you quoted from the JLS is an explanation for the single line you posted below it. So what exactly are you asking for an explanation for?
Sandip Kaviman
Ranch Hand

Joined: Apr 27, 2004
Posts: 49
according to me char c='\u000d'; should not compile ...
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

"Sandip K",
Welcome to JavaRanch!

We're pleased to have you here with us here on the ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious. You can change it here
[ March 05, 2008: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2988
Sandip, my compiler agrees with you:

Are you sure you compiled the right code?
Sandip Kaviman
Ranch Hand

Joined: Apr 27, 2004
Posts: 49
Yes, I did, might be difference in the compiler, I have
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode)

Anyway Thanks Mike

Mark Herschberg

Joined: Dec 04, 2000
Posts: 6037
"Sandip K",

Perhaps you were unclear on the naming policy after Ben's prior message. Please look carefully at the official naming policy at JavaRanch & reregister yourself with a proper first & last name, with a space between them. Initials may be used for a first name, but not a last name. Please adhere to official naming policy & help maintain the decorum of the forum. The naming policy can be found at http://www.javaranch.com/name.jsp. You can change your name here.

Consider Paul's rocket mass heater.
subject: Character Literals
Similar Threads
I am now totally confused about using char literal.Please help me.
comments and unicode - abhilash mock test
variable in comments!
char literal
char literals