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

/* HelloUtf8.java
 * Copyright (c) HerongYang.com. All Rights Reserved.
 */
public class HelloUtf8 {
   public static void main(String[] a) {
      System.out.println("Hello world!");   
      System.out.println("世界你好!");   
   }
}

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

herong> javac HelloUtf8.java

HelloUtf8.java:7: error: unmappable character (0x81) for encoding 
   windows-1252
      System.out.println("##############?");
                                        ^
1 error

The compiler used "Cp1252" as the default encoding to process the source file, HelloUtf8.java. It reported Chinese characters in UTF-8 encoding as invalid characters.

To fix this problem, you need to use the "native2ascii" tool - see the next section.

Table of Contents

 About This Book

 Java Tools Terminology

 Java Tools Included in JDK

 javac - The Java Program Compiler

 jar - The JAR File Tool

 jlink - The JRE Linker

 jmod - The JMOD File Tool

 jimage - The JIMAGE File Tool

 jpackage - Binary Package Builder

 java - The Java Program Launcher

 jdeps - The Java Class Dependency Analyzer

 jdeprscan - The Java Deprecated API Scanner

 jdb - The Java Debugger

 jcmd - The JVM Diagnostic Tool

 jconsole - Java Monitoring and Management Console

 jstat - JVM Statistics Monitoring Tool

 JVM Troubleshooting Tools

 jhsdb - The Java HotSpot Debugger

 jvisualvm (Java VisualVM) - JVM Visual Tool

 jmc - Java Mission Control

 javap - The Java Class File Disassembler

 keytool - Public Key Certificate Tool

 jarsigner - JAR File Signer

 jshell - Java Language Shell

 jrunscript - Script Code Shell

 serialver - serialVersionUID Generator

native2ascii - Native-to-ASCII Encoding Converter

 native2ascii - Encoding Converter Command and Options

javac - Using CP1252 to Process Source File

 "native2ascii -encoding" - UTF-8 to uXXXX Conversion

 Setting UTF-8 Encoding in PrintStream

 Converting uXXXX Sequences Back with "-reverse" Option

 Outdated Tutorials

 References

 Full Version in PDF/EPUB