Java: Unicode in Java

By Xah Lee. Date: . Last updated: .

Class, function, variable names can be NON-ASCII characters, such as Greek letters or math symbols.

class X {
    public static void main(String[] arg) {

    String  = "north";
    double π = 3.14159;

    System.out.println( 北 );
    System.out.println( π );

Unicode Character Escape Syntax

Any character in source code can also be represented by its Unicode number. By starting with \u followed by its 4 digits hexadecimal code.

class X2 \u007b
    static \u0069nt \u03b1 = 3;
    public static void main(String[] arg) {
    System.out.println( \u03b1 );

In the above example,

To find Unicode character and its codepoint and hexadecimal, see Unicode Search 😄

File Encoding

When saving file, make sure you save it as utf8 encoding. Your editor should have a option to do so.

If you have errors in compiling, try javac -encoding UTF8 myFileName

[see Unicode Basics: Character Set, Encoding, UTF-8]


  1. Install
  2. javac java jar javadoc

Java Basics

  1. Print String
  2. Strings
  3. Power Function
  4. Java Types and Type Conversion
  5. Function
  6. Arrays

Class, Inheritance

  1. extends
  2. Constructor
  3. Constructor Return Type
  4. Extending a Class that has Explicit Constructors
  5. static
  6. this
  7. super
  8. Access Specifiers

Abstract class, Interface

  1. abstract
  2. Interface


  1. Package


  1. Collection, Map
  2. Read/Write File
  3. Convert File Encoding
  4. Complex Numbers in Java
  5. Unicode
  6. Number Literals