Your characters are probably being corrupted by the compilation process and you're ending up with junk data in your class file.

> if i run on linux with option -Dfile.encoding=ISO-8859-1 it works properly..

[The "file.encoding" property is not required by the J2SE platform specification; it's an internal detail of Sun's implementations and should not be examined or modified by user code. It's also intended to be read-only; it's technically impossible to support the setting of this property to arbitrary values on the command line or at any other time during program execution.][1]

In short, don't use -Dfile.encoding=...

 String x = "½";

Since U+00bd (½) will be represented by different values in different encodings:

 windows-1252 BD
 UTF-8 C2 BD
 ISO-8859-1 BD

...you need to tell your compiler what encoding your source file is encoded as:

 javac -encoding ISO-8859-1 Foo.java

Now we get to this one:

 System.out.println(x);

As a [PrintStream][2], this will encode data to the system encoding prior to emitting the byte data. Like this:

 System.out.write(x.getBytes(Charset.defaultCharset()));

That may or may not work as you expect on [some platforms][3] - the byte encoding must match the encoding the console is expecting for the characters to show up correctly.


 [1]: http://bugs.sun.com/view_bug.do?bug_id=4163515
 [2]: http://java.sun.com/javase/6/docs/api/java/io/PrintStream.html
 [3]: http://illegalargumentexception.blogspot.com/2009/04/i18n-unicode-at-windows-command-prompt.html