1

I am trying to print the "white smiling face" to the console window using the following line of code in Java:

System.out.println( '\u263A' );

I do not get Smiley but some other character that looks a little like a question mark.

I am running the Windows 7 Pro operating system using jdk and jre versions 1.8.0_66 Any hints as to why?

Note: I am using the Consolas font in the console window which maps the code to the ideograph according to the character map dialogue.

Mike G
  • 4,232
  • 9
  • 40
  • 66
  • 2
    your command prompt may have different coding like ISO-XXXX – PeerNet Jan 06 '16 at 22:03
  • 5
    You can output exactly the same 16-bit "Unicode code point" to a Windows command prompt, a notepad text file, a Linux terminal or an MS-Word file ... and you might see four different "characters" rendered. Extraordinarily helpful link: [The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)](http://www.joelonsoftware.com/articles/Unicode.html) – paulsm4 Jan 06 '16 at 22:07

1 Answers1

1

This is not really a problem in your code. As commenters have pointed out, there is a difference between writing a Unicode code point and how your applications or OS choose to render a sequence of bytes as a character. Here is what I get on Mac:

> javac TestWhiteSmilingFace.java && java TestWhiteSmilingFace
☺

The Windows console does not support Unicode output though. Instead, it operates on Windows Code Pages.

If you are willing to pipe output to a separate file and then open it in Notepad, then here is an approach that has worked successfully for me.

  1. Start cmd.exe with the /U option. As discussed in cmd documentation, This option forces command output redirected to a file to be in Unicode.
  2. Redirect the command output to a file, i.e. java TestWhiteSmilingFace > TestWhiteSmilingFace.txt.
  3. Open the file in Notepad, i.e. notepad TestWhiteSmilingFace.txt.

This prior answer discusses the Windows console Unicode limitation in more detail and also suggests using the PowerShell Integrated Scripting Environment as a potential workaround.

Printing Unicode characters to the PowerShell prompt

Community
  • 1
  • 1
Chris Nauroth
  • 9,614
  • 1
  • 35
  • 39
  • 2
    Thanks Chris. Key was " Windows console does not support Unicode." There is another good discussion on this same topic at http://stackoverflow.com/questions/1259084/what-encoding-code-page-is-cmd-exe-using – Garrett A. Hughes Jan 06 '16 at 22:40