Powershell Core 7 is apparently natively BOM-less UTF8 but it still performs exactly the same as Windows Powershell when I use javac
on any UTF8 source file that contains accented characters : it encodes the .class
file with ANSI character encodings.
For example, this simple program PremierProg.java
:
public class PremierProg
{
public static void main( String[] args )
{
System.out.println("Je suis déterminé à apprendre comment coder.");
}
}
will be compiled then executed with the following output in pwsh
:
Je suis déterminé à apprendre comment coder.
I can very obviously add the -encoding "UTF-8"
option to my javac
call, but isn't the point of cross-platform not having to do any of that? It is actually easier to type wsl javac [MySource.java]
and have it output the correct .class
file. The same versions of openjdk are installed on both the Windows and Ubuntu sides.
Powershell does read the file correctly as UTF8 :
but still interacts with javac
using ANSI (even though other forever-utf8-native shells like bash don't have this issue).
Does anyone know why Powershell - even the cross-platform Core version - behaves this way? I really don't want to add anything to a profile.ps1 file or to the javac call. I would just like something that is UTF8-native to fully behave that way.
At the moment, I am getting my students to run bash (via wsl) as their default shell, and that's fine, but this problem still bothers me. I'd like to understand what is going on, and if the solution is at all reasonable, fix it.
The reason for not wanting a profile.ps1 file or extra parameters in the javac call is because this needs to run on school-board controlled devices where scripts are disabled and I am dealing with a majority of first-time programmers.