This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bogus Error in NetBeans 6.8 Editor

 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 . . .

 
Campbell Ritchie
Sheriff
Posts: 48402
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or here, try the improved version that requires no imports nor the console:

 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic