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.
- 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.
- Redirect the command output to a file, i.e.
java TestWhiteSmilingFace > TestWhiteSmilingFace.txt
.
- 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