File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes unicode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "unicode" Watch "unicode" New topic
Author

unicode

Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
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


Thanks,<br />Thiru<br />[SCJP,SCWCD,SCBCD]
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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.


Dave
Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
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

Joined: May 10, 2001
Posts: 3244
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

Joined: Aug 29, 2001
Posts: 219
thanks dave. I got it.
Francisco A Guimaraes
Ranch Hand

Joined: Mar 20, 2002
Posts: 182
what�s \u000a ?


Francisco<br />SCJP<br />please use the [code][/code] tags when showing code.Click <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank" rel="nofollow">here</a> to see an example.
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

\u000a is the NewLine character -- check out This chart-o-unicode characters from unicode.org
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: unicode
 
Similar Threads
Wrapper class
equals method behavior of Float
float f= \u0038
Comparison of arrays
equals()