(Probably simple) problem with displaying Unicode characters

Discussion in 'Java' started by mfeher@stny.rr.com, Feb 28, 2006.

  1. Guest

    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
    , Feb 28, 2006
    #1
    1. Advertising

  2. 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/
    Knute Johnson, Feb 28, 2006
    #2
    1. Advertising

  3. Roedy Green Guest

    On Tue, 28 Feb 2006 10:24:40 -0800, Knute Johnson
    <> wrote, quoted or indirectly quoted someone
    who said :

    >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.


    Isn't that weird that the console remained stuck at the stage of
    evolution of DOS. On my machine, it even uses the old IBM OEM char
    set.

    It needs an update: colour, traceback to the source line that created
    it, Tee to a file, scrollback, permanent log record, encodings.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Feb 28, 2006
    #3
  4. Zerex71 Guest

    Hi Knute,

    Thanks for responding. The funny thing is, I think anyone reading this
    post must think I've gone mad, because looking at my code now, the beta
    displays just fine. It did not, however, when I tried posting - it
    came up looking like a "careted" capital I to the power of 2.

    My question then becomes:
    1. Is my code at all buggy? (I maintain that it's not and that it's
    perfectly legal; maybe I'm using the wrong encoding? I got it from an
    online example).
    2. Do I have a possible font problem?

    I forgot to mention perhaps that the output is being sent to the
    Eclipse debug/output console, and that's where it's not displaying
    properly.

    Mike
    Zerex71, Feb 28, 2006
    #4
  5. Oliver Wong Guest

    "Zerex71" <> wrote in message
    news:...
    > Hi Knute,
    >
    > Thanks for responding. The funny thing is, I think anyone reading this
    > post must think I've gone mad, because looking at my code now, the beta
    > displays just fine. It did not, however, when I tried posting - it
    > came up looking like a "careted" capital I to the power of 2.
    >
    > My question then becomes:
    > 1. Is my code at all buggy? (I maintain that it's not and that it's
    > perfectly legal; maybe I'm using the wrong encoding? I got it from an
    > online example).
    > 2. Do I have a possible font problem?
    >
    > I forgot to mention perhaps that the output is being sent to the
    > Eclipse debug/output console, and that's where it's not displaying
    > properly.


    I've never seen anyone setting the encoding on a printstream directed to
    the console before. Presumably, the OS (or Eclipse in this case), will set
    up the encoding the way it likes, so setting it differently might mess
    things up.

    - Oliver
    Oliver Wong, Feb 28, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jonas

    Displaying Unicode characters

    Jonas, Mar 8, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    3,138
    Juan T. Llibre
    Mar 9, 2005
  2. =?Utf-8?B?Q2hyaXN0aWFuIE51bmNpYXRv?=

    Posted Unicode Characters Displaying as "???"

    =?Utf-8?B?Q2hyaXN0aWFuIE51bmNpYXRv?=, May 8, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    580
    =?Utf-8?B?Q2hyaXN0aWFuIE51bmNpYXRv?=
    May 8, 2005
  3. Jay Brahms
    Replies:
    5
    Views:
    1,808
    Anthony Simuel
    Jun 28, 2006
  4. Shankar
    Replies:
    8
    Views:
    12,958
    krassif
    Oct 15, 2009
  5. Grzegorz ¦liwiñski
    Replies:
    2
    Views:
    940
    Grzegorz ¦liwiñski
    Jan 19, 2011
Loading...

Share This Page