File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes unicode value for char Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "unicode value for char" Watch "unicode value for char" New topic
Author

unicode value for char

abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635


I want to show the unicode value of input character but it does not work
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3071
    
  33

Please TellTheDetails ItDoesntWorkIsUseless


Mohamed Sanaulla | My Blog
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
System.in.read() reads a byte, not a char (a char is two bytes). To show this, try running the following code:
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
Thanks tom,

I want the code show this: "\u0633",But it doesn't

This is output of your code:

please enter a char
س
numRead = 2
-45 10 please enter a char
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

Remember, for character data we don't use InputStream, we use Reader. Wrap a Reader around System.in, using the correct encoding, and then you can read one character at a time.
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
Thank you

Look at this code:





The output is :

س


Now my question:

I want that code return \u0633 when I enter س I had posted.

It java itself convert \u0633 to س, Then why it couldn't convert س to \u0633

This is code that I wrote:



ouput:

633


I want it shows this "\u0633" without add "u" or "\" in the program, by programmer.

Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
Will this be acceptable?
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
What is the simplest way in java in order to convert unicode to character?

\u0633 conver to س

Is this correct:

UTF8 is a standard for unicode encoding.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

Abalfazl, I get the impression you are confused about the meaning of \u0633.

Any of the \uxxxx tokens in Java source code will be read by Java's 'precompiler', and automatically converted to their char representation. This all happens before the source code is actually compiled. This is done in the entire file, including comments, strings and other code.
It's simply a way you can enter unicode characters in your source file without being able to type their actual character representation. Outside of the precompiler, these tokens have no meaning.

There is no simplest way of converting \u0633 to س, because they already mean exactly the same thing, as far as Java in concerned.

What is it exactly you want to do?

As for your question regarding UTF-8, what have you found out for yourself?
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
Thanks, I want to understand unicode deeply.



Is there easier way to convert \u0633 to س

Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3649
    
  17

What do you mean by convert? To print the graphical glyph representing the unicode character? Then no, this should be simple enough.
abalfazl hossein
Ranch Hand

Joined: Sep 06, 2007
Posts: 635
I have question about this line:



This prototype is from:http://download.oracle.com/javase/1.4.2/docs/api/java/io/PrintStream.html



Is System.out instance of OutputStream?May you explain about the this redirect mechanism?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14338
    
  22

abalfazl hossein wrote:Is System.out instance of OutputStream?

You can find the answer to this question in the documentation of class java.lang.System.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39791
    
  28
Jesper de Jong wrote:
abalfazl hossein wrote:Is System.out instance of OutputStream?

You can find the answer to this question in the documentation of class java.lang.System.
. . . or . . .
Lovro Bajc
Ranch Hand

Joined: Jun 28, 2014
Posts: 45
Hi everyone. I have a far more beginners question I guess.

currently I am at the 4th section in the book called Introduction to Java programming, comprehensive version 10, by Y.Daniel Lang.

I have a task to print out the unicode of the entered character by user. Here is the code so far:


I dont know/ have no clue how to get the value out for a character.

Can you please assist me on this problem.

thanks for your time, review and answer.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
Tom Reilly's second post in this topic shows how to do it.


Ping & DNS - my free Android networking tools app
 
Don't get me started about those stupid light bulbs.
 
subject: unicode value for char