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.
February 18th, 2013 at 5:06 PM
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.
February 18th, 2013 at 5:16 PM
What’s more, in version 5 and earlier, there isn’t even a consistent default across all classes: see this StackOverflow page.
February 18th, 2013 at 6:30 PM
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
February 19th, 2013 at 8:24 AM
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
February 27th, 2013 at 2:07 AM
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]
March 31st, 2013 at 10:51 AM
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
March 31st, 2013 at 10:53 AM
Ooops, didn’t notice until too late you were only looking for Windows.
May 24th, 2013 at 4:31 PM
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
May 24th, 2013 at 4:38 PM
If I run this from within Eclipse 3.7 using jdk1.7.0_21 I get “UTF-8”.
July 22nd, 2013 at 10:25 PM
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.