permaculture playing cards
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes strange problem in comments. 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 "strange problem in comments." Watch "strange problem in comments." New topic

strange problem in comments.

sony ali

Joined: Feb 24, 2001
Posts: 9
hi: i mfacing a strange problem in comments. ie
i have a code
public class ali{

//char a='\u00A'
problem: whan i m compiling this code, the code s not compiling. i donot know why the compiler s reading single line coments?

second thing:
see this code
public class ali{
//int a= 2;
//byte b= 2;
//float f= 2;
//double d=2;
//in all other cases compiling
problem 2: when i mcompiling this code , it compile successfully.
plz explain the difference of these two problems.
love to all
Hima Mangal
Ranch Hand

Joined: Feb 25, 2001
Posts: 82
hi sony,
i think this is because the escape sequence '\u000A' stands for a special character, that is the carriage return character so that ur code
char c='\u000A'; is equivalent to
char c=
that is, the compiler performs the unicode conversion while compiling and results in compiler error.
pls correct me if i am wrong.

Hima<BR>Sun Certified Java Programmer
Naveed Hassan

Joined: Feb 23, 2001
Posts: 17
but why the compiler is not ignoring the rest of the line by finding comment symbol==> // on the start of the line
sony ali

Joined: Feb 24, 2001
Posts: 9
hi : hina mangal
actully my question s that as we know that "when a line having single line comments . it s not read by the compiler". so why here the compiler is reading this (//char a= \u000A)explain me.
Paul Anilprem
Enthuware Software Support
Ranch Hand

Joined: Sep 23, 2000
Posts: 3634
The reason is such unicode escape sequences are converted to appropriate characters in "pre" compilation step. It's true that the compiler won't look at anything after // in that line, but //char a='\u00A' is converted to:
//char a='
even before the compiler starts working on it.

Get Certified, Guaranteed!
(Now Revised for the new Pattern)

[This message has been edited by Paul Anil (edited March 26, 2001).]

Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
I agree. Here's the link:
subject: strange problem in comments.
It's not a secret anymore!