• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unicode

 
Thiru Thangavelu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference f1 and f2? The second one is unicode char which is assinged to float, which is legal. But what about f1? I looks different. What is it actually assigning?
class Test {
public static void main(String [] args) {
float f1 = \u0038;
float f2 = '\u0038';
System.out.println(f1); //8.0
System.out.println(f2); //56.0
}
}
Thanks
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thiru
When the code is compiled the unicode is translated and the character value is sustituted very early in the compiling process.
In your code after the compiler does all of the unicode sustitutions it looks like this:
float f1 = 8;
float f2 = '8';
Then when the code is run it prints the values out:
the float value of 8 is 8
the float value of the value of the character literal 8 is 56.
hope that made sense.
 
Thiru Thangavelu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dave
I thought unicode but unicode should be enclosed like this '\u0038'
what sort of form is this?
float f1 = \u0038;
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thiru
The unicode character begins with the escape \ character and ends with the 4th digit in the number. Regardless of where it occurs in the code the character value is substituted for the escaped unicode. Put this line in your code and see what it prints:
System.out.println("hi boy\u0008b");
Now try \u000A
 
Thiru Thangavelu
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks dave. I got it.
 
Francisco A Guimaraes
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what�s \u000a ?
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\u000a is the NewLine character -- check out This chart-o-unicode characters from unicode.org
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic