cyrillic in windows Console(java) System.out.println();

Solution 1:

import java.io.PrintStream;
class Kyrill {
    public static void main(String args[])
        throws java.io.UnsupportedEncodingException
    {
        String ru = "Русский язык";
        PrintStream ps = new PrintStream(System.out, true, "UTF-8");
        System.out.println(ru.length());
        System.out.println(ru);
        ps.println(ru);
    }
}

D:\Temp :: chcp 65001
Aktive Codepage: 65001.

D:\Temp :: javac -encoding utf-8 Kyrill.java && java Kyrill
12
??????? ????
Русский языкй язык

Note that you might see some trailing junk in the output (I do) but if you redirect the output to a file you'll see that this is just a display artefact.

So you can make it work by using a PrintStream. The System.out uses the platform encoding (cp1252 for me), and that doesn't have cyrillic characters.

Additional note for you to grok the encoding business:

D:\Temp :: chcp 1251
Aktive Codepage: 1251.
:: This is another codepage (8 bits only) that maps bytes to cyrillic characters.
:: Edit the source file to have:
::      PrintStream ps = new PrintStream(System.out, true, "Windows-1251");
:: We intend to match the console output; else we won't get the expected result.
D:\Temp :: javac -encoding utf-8 Kyrill.java && java Kyrill
12
??????? ????
Русский язык

So you can see that contrary to what some people believe, the Windows console does grok Unicode in the casual sense that it can print Greek and Russian.

Solution 2:

Although you can switch Windows console to UTF-8 by chcp 65001, you may still not be able to view UTF-8 output properly. This may not be what you want, but it at least is a choice: redirect your standard output to a file. Save your source file as UTF-8 and compile it using UTF-8 encoding. The redirected output file can be viewed with a UTF-8 aware text editor.

String s = "Русский язык";
System.setOut(new PrintStream(new FileOutputStream("out.txt"), true, "UTF-8"));
System.out.println(s);