Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes IDEs, Version Control and other tools and the fly likes Bogus Error in NetBeans 6.8 Editor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Bogus Error in NetBeans 6.8 Editor" Watch "Bogus Error in NetBeans 6.8 Editor" New topic
Author

Bogus Error in NetBeans 6.8 Editor

Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
Using NB 6.8 out of the box I get an
"Illegal unicode..." error simply by typing:

// '\u

Is this not a valid comment line?
Help . . .



BEE MBA PMP SCJP-6
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40041
    
  28
Welcome to JavaRanch

If I remember correctly, the \u characters are converted from \u1234 to whatever (1234 looks like a wishbone and is pronounced "see" in Ethiopian), before the text is compiled. So the \u conversion is carried out before //, so you ought to avoid \u in comments.
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
The official Sun "Java Programming Language" book by
Arnold/Gosling/Holmes says,

"[Comments] play no part in the generation of code and
so are ignored during scanning." and that "Characters
from // to the end of line are ignored."

So my question still stands. It really looks like a bug in
the NetBeans 6.8 distribution. Please try it in your IDE.

Jim...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

That quote is somewhat wrong. \uXXXX sequences are processed first, only after that does the quote hold.

Replace the \ with its HTML counterpart \ - the browser will replace that with \ when you open the generated HTML file.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Jim Hoglund wrote:The official Sun "Java Programming Language" book by
Arnold/Gosling/Holmes says,

"[Comments] play no part in the generation of code and
so are ignored during scanning." and that "Characters
from // to the end of line are ignored."

So my question still stands. It really looks like a bug in
the NetBeans 6.8 distribution. Please try it in your IDE.

Jim...


So you've tried other IDE's and also the command line compiler and not had a problem? Personally, I think that this is a Java compiler issue, not NetBeans, and that it's not a bug.
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
As an example, here is, what I must modestly state, one of the very best programs that I've ever written. Please try to run it (don't forget the import and the comments) and see if you agree:

Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
Pete - I'm quite confused. I copied your pgm into
NetBeans, cleaned up my errors and hit SHIFT-F6
to run the file. It did nothing, as I would expect.
It seems that the "//" comments are being treated
as comments. Is there another message you are
trying to convey? What am I missing?

Jim...
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Jim Hoglund wrote:Pete - I'm quite confused. I copied your pgm into
NetBeans, cleaned up my errors and hit SHIFT-F6
to run the file. It did nothing, as I would expect.
It seems that the "//" comments are being treated
as comments. Is there another message you are
trying to convey? What am I missing?

Jim...


What do you mean by "cleaned up my errors"? There should be no errors. If you get the code to run,... and it should run, it will all be self-explanatory. If when you paste it, the compiler says that you have errors, then something is not right.

Please try it again and let me know what errors you are seeing before you clean them up.

The program should display text in NetBeans Console window. Do you have this displayed?
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Or here, try the improved version that requires no imports nor the console:

Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
Pete Stein is great!

I bet you just wanted to see this one more time.
Now you've got some serious "splain-in" to do . . .
This time the only error I fixed was to remove
the line numbers.

Jim...
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Jim Hoglund wrote:Pete Stein is great!

Ain't it the truth! Ain't it the truth!


Now you've got some serious "splain-in" to do . . .

Per the JLS,
Programs are written using the Unicode character set.


the \uXXXX are each unicode characters and are thus part of the Java code. The first character after the comment slashes, \u000A represents a new line, so all the characters that follow are on that new line -- meaning they are no longer part of a comment and are actually compilable code.

So while contrived, this shows that even though you may have text in a comment, it may still, in certain situations affect your code.
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
Okay, now it's back to where this topic began.
Consider:

if (charX == '\u0000') {} // Life is good, or
if (charY == '\u00FF') {} // Life is still good, but with
if (charZ == '\u000A') {} // There is trouble a-brewing.

The "Java Programming Language" book I mentioned
above dumps you into this hole with its exercise 10.1.
(Just the big boys having some fun.)

Jim...
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Jim Hoglund wrote:Okay, now it's back to where this topic began.
Consider:

if (charX == '\u0000') {} // Life is good, or
if (charY == '\u00FF') {} // Life is still good, but with
if (charZ == '\u000A') {} // There is trouble a-brewing.

The "Java Programming Language" book I mentioned
above dumps you into this hole with its exercise 10.1.
(Just the big boys having some fun.)

Jim...


Again, the problem is you have the actual char for new line in the last if condition. These two bits of code are equivalent:
code 1:


code 2:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bogus Error in NetBeans 6.8 Editor