This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 3068
    
  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: 3600
    
  14

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: 3600
    
  14

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: 3600
    
  14

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: 14074
    
  16

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 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38044
    
  22
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
Greenhorn

Joined: Jun 28, 2014
Posts: 24
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: 41133
    
  45
Tom Reilly's second post in this topic shows how to do it.


Ping & DNS - my free Android networking tools app
 
jQuery in Action, 2nd edition
 
subject: unicode value for char
 
Similar Threads
please explain the reason behind the output of this code
char literal
can you increment letters?
ASCII - UNICODE
int and char