Re: (Probably simple) problem with displaying Unicode characters



mfeher@xxxxxxxxxxx wrote:
Hi all,

I am getting back into Java programming after a long layoff and now
that I'm doing it everyday, I'm remembering the things I enjoyed about
it and the things that I find maddening. :) I'm trying to write a
simple program to both test my old skills as well as develop code for
use later, when I will need it on a later project.

Right now I'm simply trying to display a Unicode character in the
Eclipse output window. I have a full-up WinXP system with a ton of
fonts (more on that in a moment) but don't seem to see what is wrong
with my program.

I never did much with Unicode years before and never had it succeed for
me then, either, if I recall correctly. But I don't think the
process/requirements are that hard:

- Have Unicode fonts installed
- Use the correct encoding in the Java output stream
- Look up the correct character(s) in the Unicode tables

Here's the program as it stands now (one file called Main.java):


import java.io.*;

public class Main {

/**
* @param args
*/
public static void main(String[] args) throws
UnsupportedEncodingException {
String unicodeMessage = "\u03B2";

// Print out a Unicode character
System.out.println("We attempt to print out the Greek character
beta:");
PrintStream output = new PrintStream(System.out, true, "UTF-8");
output.println(unicodeMessage);
}
}

Here's the output I get:

We attempt to print out the Greek character beta:
β


Please, can someone spot the (probably simple) error in my
setup/coding? Thanks!

Mike


Mike:

The default character set is UTF-16 which will display your 'beta' character just fine. It won't however display on the console, at least I know it won't on a Winblows XP system.

import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class Main {

/**
* @param args
*/
public static void main(String[] args) throws UnsupportedEncodingException {
Frame f = new Frame();
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
f.add(new Label("\u03b2"));
f.pack();
f.setVisible(true);
}
}

--

Knute Johnson
email s/nospam/knute/
.



Relevant Pages

  • Re: VB - Ascii to Unicode and then Unicode to UTF-8 conversion (Very desperate!!)
    ... Latin together) then you have to use a Unicode column type. ... AscW returns the real Unicode character ... for Chinese characters, ... then the next thing to worry about is your CSV file. ...
    (microsoft.public.vb.general.discussion)
  • Re: Unicode Support
    ... if two Unicode strings are the same? ... UTF-16 is basically telling everyone "ok we all got to start ... character, and will likely support *both* endians. ... UTF-8 encodings are also easy to learn to ...
    (alt.lang.asm)
  • Re: Determining if a string is Unicode
    ... there's nothing magic about Unicode. ... where each character occupies 2 bytes, as opposed to a Single-Byte Character ... You could load up a string with rubbish, ... > INF file like so: ...
    (microsoft.public.vb.general.discussion)
  • Re: KANJD212
    ... >>Who decides the factors and what are their criteria, Unicode? ... But once a character is defined/get a codepoint in Unicode it ... standard modifies the codepoint of the kanji to a totally new ... I can use a code like JIS X0208 along with a font ...
    (sci.lang.japan)
  • Re: Enhanced Unicode support for "Go" tools
    ... the point to remember is that UNICODE is a _character ... It's the fonts, the OS and the application which work together ... society for the protection of French from English ...
    (alt.lang.asm)