I got a JAVA Problem

Status
Not open for further replies.

ajayNCSTian

Right off the assembly line
Hello Everybody

Why following Commented Statement JAVAC cannot compile ??

public class Unicode
{
public static void main(String[] args)
{
//char a = '\u007';
/*char b = '\u007'*/;
}
}

It is understandable that Unicode escape should follow 4 digits after it
But why such a rule in commented statement ?
What is the reason behind this :?:
 

sujithtom

Ambassador of Buzz
I am no Java programmer but I don't think you can use the name Unicode as it is a reserved word. Specify you error message
 
OP
A

ajayNCSTian

Right off the assembly line
Oops My mistake ... :wink:
The Error message is :
"Illegal Unicode character." at line <so and so>

The class name is not taken by intension. I mean to say whatever you
take class name .. Error remains the Same.

Now how about it? :?
 

GNUrag

FooBar Guy
ajayNCSTian said:
//char a = '\u007';
/*char b = '\u007'*/;

The javac compiler makes several passes on the source code before it even checks keywords and classes... In this case, '\u007' is not a valid unicode character...

Since u're doing a program in Unicodes, you should know that unicode escape sequences are composed of a leading \u and four HEX characters...

Even when the code is commented, it will give error since, all the code is first parsed and all the unicode/hex/octal escape sequences are checked before actually compiling it...
 

#/bin/sh

Journeyman
Unicode characters are valid characters even in for your source code. Thus, the compiler sees the \u and expects a valid unicode.

Insert the following line and see that the compiler flags the last '; as an invalid constant character.

// char c = '\u000A';

\u000A is a linefeed and thus the '; begins a new source line which is a compile error.

\u followed by 4 hexadecimal characters!
Now, // String a ="sasasas\uasasasas";
 

#/bin/sh

Journeyman
The problem is just with \u in comments

even the strings like
// String a ="sasasas\uasasasas";
will not work
 
Status
Not open for further replies.
Top Bottom