Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

(Probably simple) problem with displaying Unicode characters

Thread view: 
mfeher@stny.rr.com - 28 Feb 2006 15:20 GMT
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
Knute Johnson - 28 Feb 2006 18:24 GMT
> Hi all,
>
[quoted text clipped - 47 lines]
>
> 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);
    }
}

Signature

Knute Johnson
email s/nospam/knute/

Roedy Green - 28 Feb 2006 19:17 GMT
On Tue, 28 Feb 2006 10:24:40 -0800, Knute Johnson
<nospam@ljr-2.frazmtn.com> 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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Zerex71 - 28 Feb 2006 22:03 GMT
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
Oliver Wong - 28 Feb 2006 22:06 GMT
> Hi Knute,
>
[quoted text clipped - 12 lines]
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.