Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Literal Line feed

 
Pal Sudarshan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When I compile the code below, I get an error message stating, "illegal line end in character literal" What is reason for that? When and how can we use this literal then?

 
Chris Allen
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pal Sudarshan:
Hi,

When I compile the code below, I get an error message stating, "illegal line end in character literal" What is reason for that? When and how can we use this literal then?



During the compilation process, the unicode character \u000A gets converted to the end of line character which causes the compiler error. You can use '\n' for newline instead.
 
Pal Sudarshan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, thank you for the reply.

Why does it cause compiler error? "It gets converted to end of line." If it gets end of line, what is the problem with that? Why doesn't it do the same function as '\n'? If it is in the language, then where can we use the literal?

Again, thanks for the reply.
 
Robert Miller
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with that code is the compiler converts unicode characters before it parses the code. Therefore, the java compiler will end up seeing a line that looks like:

char c = '
';

which is illegal. I don't know the exact sequence the compiler goes through, but I suppose you could use unicode sequences to build up keywords and that would also work.

In any case, the compiler does not convert '\n' before parsing the code, so use that instead of '\u000A'.

Robert
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic