Quick Java Favor

If anyone out there has the JDK installed on Windows, could you run this program and tell me what output you get, and what version of Windows and the JDK you’re using?

import java.nio.charset.*;

public class URLtest {
    public static void main(String[] args) {
        System.out.println(Charset.defaultCharset());
    }
}

Just leave a comment with the info. Thanks.

10 Responses to “Quick Java Favor”

  1. John Cowan Says:

    On Windows XP SP3 (standard U.S. version), I compiled and ran this twice, once with JDK 1.6.0_38 and once with JDK 1.7.0_11. In both cases the answer was “windows-1252”, which is what I’d expect.

  2. John Cowan Says:

    What’s more, in version 5 and earlier, there isn’t even a consistent default across all classes: see this StackOverflow page.

  3. Michael McEniry Says:

    windows-1252
    Windows 7 Home Premium, SP1, 64-bit, using US English settings
    Compiled and run with Oracle JDK 1.7.0_13, 64-bit

  4. Jez Higgins Says:

    Windows 7 Enterprise SP1, 64 bit, with UK English settings

    c:\temp>java -version
    java version “1.6.0_38”
    Java(TM) SE Runtime Environment (build 1.6.0_38-b05)
    Java HotSpot(TM) 64-Bit Server VM (build 20.13-b02, mixed mode)

    c:\temp>java URLtest
    windows-1252

  5. Todd Trimmer Says:

    It’s all 32-bit.

    $ java -version
    java version “1.7.0_13”
    Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
    Java HotSpot(TM) Client VM (build 23.7-b01, mixed mode)

    $ java -cp . URLtest
    windows-1252

    $ cmd /C ver

    Microsoft Windows XP [Version 5.1.2600]

  6. Bill Goggin Says:

    Oracle Java

    $ java -version
    java version “1.7.0_17”
    Java(TM) SE Runtime Environment (build 1.7.0_17-b02)
    Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

    OS X 10.8.3

    $ java URLtest
    UTF-8

  7. Bill Goggin Says:

    Ooops, didn’t notice until too late you were only looking for Windows.

  8. Jan Says:

    C:\>”C:\Program Files (x86)\Java\jdk1.7.0_21\bin\javac.exe” URLtest.java

    C:\>”C:\Program Files (x86)\Java\jdk1.7.0_21\bin\java.exe” URLtest
    windows-1252

    C:\>”C:\Program Files (x86)\Java\jdk1.6.0_45\bin\javac.exe” URLtest.java

    C:\>”C:\Program Files (x86)\Java\jdk1.6.0_45\bin\java.exe” URLtest
    windows-1252

    OS Name: Microsoft Windows 7 Professional
    OS Version: 6.1.7601 Service Pack 1 Build 7601

  9. Jan Says:

    If I run this from within Eclipse 3.7 using jdk1.7.0_21 I get “UTF-8”.

  10. Rick Jelliffe Says:

    On the Stack Overflow page John mentioned: I think some of the readers are confused on that page: they are surprised they cannot set the default encoding, perhaps thinking it means the default used throughout Java I suppose, where it probably is supposed to be a read-only property to reveal what the OS uses (or what Java thinks the OS uses.)

    Now that there is so much of the ecosystem generating UTF-8 (.NET, Macs, etc), I see less and less use of other encodings.

Leave a Reply