'javac' Using CP1252 to Process Source File

This section provides a tutorial example showing how 'javac' processing Java source code files with CP1252 encoding.

In order to test the "native2ascii" tool, I wrote the following Java source code file: HelloUtf8.java

public class HelloUtf8 {
   public static void main(String[] a) {
      System.out.println("Hello world!"); 	

"HelloUtf8.java" contains a string of Chinese characters written in UTF-8 encoding. When I tried to compile it, I got the following warning:

C:\herong>javac HelloUtf8.java

HelloUTF8.java:4: warning: unmappable character for encoding Cp1252
1 warning

The compiler used "Cp1252" as the default encoding to process the source file, HelloUtf8.java. The last character of my Chinese string encoded in UTF-8 can not be mapped to any CP1252 character. But the compiler did finish the compilation. The output HelloUtf8.class can still be executed in JVM:

C:\herong>java HelloUtf8

Hello world!

But the last character was compiled as a question mark "?" character. To fix this problem, you need to use the "native2ascii" tool - see the next section.

Last update: 2015.

Table of Contents

 About This Book

 Java Tools Terminology

 Installing Java 8 on Windows

 'javac' - The Java Program Compiler

 'java' - The Java Program Launcher

 'jdb' - The Java Debugger

 'jconsole' - Java Monitoring and Management Console

 'jstat' - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jvisualvm (Java VisualVM) - JVM Visual Tool

 'jar' - The JAR File Tool

 'javap' - The Java Class File Disassembler

 'keytool' - Public Key Certificate Tool

'native2ascii' - Native-to-ASCII Encoding Converter

 'native2ascii' - Encoding Converter Command and Options

'javac' Using CP1252 to Process Source File

 UTF-8 to \udddd Conversion with 'native2ascii -encoding'

 Setting UTF-8 Encoding in PrintStream

 Converting \udddd Sequences Back with "-reverse" Option

 Outdated Tutorials


 PDF Printing Version