Default java encoding

Default java encoding

von Anton Dil -
Anzahl Antworten: 4

I believe it depends on the operating system defaults, but we have found that our compiler is expecting US-ASCII encoding for java source code.

Would it be worth making -encoding UTF-8 the default setting in the question prototypes? (I know I can set this using Advanced Customisation settings.)

Test code:

System.out.println("Default Charset=" + java.nio.charset.Charset.defaultCharset());

Thanks,

Anton

Als Antwort auf Anton Dil

Re: Default java encoding

von Tim Hunt -

Just to give the origin of this, it came from a question where the answer needed to be something like

System.out.println("The prize was £10.");

which is currently giving an error like


Moodle tends to force everything to UTF-8 encoding, so it there are simple compiler and/or run-time flags to get Java to expect that, then then that is probably the best thing to do.

Als Antwort auf Tim Hunt

Re: Default java encoding

von Richard Lobb -

I'm not sure I understand the full context here. But it looks like the Jobe server on which this job was run hasn't had the locale set properly as per the install instructions here. Certainly the example code you've given works fine when I run it on my development system (and I expect on all other systems we run, too).

Als Antwort auf Richard Lobb

Re: Default java encoding

von Tim Hunt -

Strangely, when we run

echo $LANG

from the shell on the Jobe server, it says en_GB.UTF-.

However, if I go to a Java CodeRunner question, and run the code

int sumSquares(int[] data) {
System.out.println(String.format("LANG environment variable: %s", System.getenv("LANG")));
System.out.println(String.format("file.encoding: %s", System.getProperty("file.encoding")));
System.out.println(String.format("defaultCharset: %s", java.nio.charset.Charset.defaultCharset().name()));
return 0;
}

That gives

LANG environment variable: C
file.encoding: ANSI_X3.4-1968
defaultCharset: US-ASCII

We are continuing to investigate, but in the mean time, if you have any more clues, that would be appreciated.

Als Antwort auf Tim Hunt

Re: Default java encoding

von Richard Lobb -

I think the problem is that the job execution is initiated by Apache. The Jobe install instructions show how to set the Apache envvars (environment variables) to change from the default C/ASCII environment to something that's UTF-8 aware. It's those environment variable settings that are controlling the jobe task execution, not the OS/Shell environment.