• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

unclosed literal

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class Char
{
public static void main(String[] args)
{
String s1="\u000a";
String s2="\u000d";
System.out.println(s1+""+s2);
}
}

hai guys, when i ran the program it was saying "unclosed literal:compile error"
can u clarify this thing?
thanks in advance
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here "\u000a" is a special unicode character,"Linefeed Character" i.e "\n"
therefore
String s1="\u000a";
becomes s1=
;
so nothing is assigned to s & hence it is giving error "unclosed literal:compile error"

same is true for "\u000d" as this is "carriage return" i.e "\r" character
Correct me if i am wrong

Regards
-Swati
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

'\u000a' and '\u000d' are Unicode values for "newline" and "carriage return" characters. These values should not be used to represent newline and carriage return in the source code. These values are interpreted as line-terminator characters by the compiler, and will cause compile time errors.

we should use the string literals "\n" and "\r", respectively, for correct interpretation of the characters "\u000a" and "\u000d" in the source code.
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The compiler translates Unicode characters at the beginning of the compile cycle.

Using the Unicode escape characters \u000A for newline and \u000D for return in a String or comment produces a compile-error as they are interpreted, literally, as 'end-of-line'.

Always use the special characters '\n' or '\r'.


Here is certain special characters which can be represented by escape sequences for your information.

\n \u000A newline
\t \u0009 tab
\b \u0008 backspace
\r \u000D return
\f \u000C form feed


As these are special characters not having any literal value. when you try to convert them to string object compiler checks whether its a valid character or not.Thats why you getting a compiler error.

Please let me know if you need any further assistance in this regard,

Thanks,
Somasekar.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic