Thursday 2 April 2020

What are connecting characters in Java while defining identifiers?

As per Java specification, identifiers must start with a letter, $, or a connecting character such as underscore ( _ ).

Following table summarizes the characters that come under connector category.
Unicode number
Name
Symbol
U+005F 
LOW LINE   
_
U+203F 
UNDERTIE   
U+2040 
CHARACTER TIE  
U+2054 
INVERTED UNDERTIE  
U+FE33 
PRESENTATION FORM FOR VERTICAL LOW LINE
U+FE34 
PRESENTATION FORM FOR VERTICAL WAVY LOW LINE      
U+FE4D 
DASHED LOW LINE
U+FE4E 
CENTRELINE LOW LINE
U+FE4F 
WAVY LOW LINE  
U+FF3F 
FULLWIDTH LOW LINE 
_

App.java
package com.sample.app;

public class App {

 public static void main(String args[]) {
  int _ = 10, ‿ = 20, ⁀ = 30, ⁔ = 40, ︳ = 50, ︴ = 60, ﹍ = 70;

  System.out.println("_ : " + _);
  System.out.println("‿ : " + ‿);
  System.out.println("⁀ : " + ⁀);
  System.out.println("⁔ : " + ⁔);
  System.out.println("︳ : " + ︳);
  System.out.println("︴ : " + ︴);
  System.out.println("﹍ : " + ﹍);
 }

}

Output
_ : 10
‿ : 20
⁀ : 30
⁔ : 40
︳ : 50
︴ : 60
﹍ : 70

Apart from the above table, there are many characters that you can use as first character while defining identifier in Java. Use the method ‘Character.isJavaIdentifierStart’ to check whether you can use given character as first character or not while defining an identifier.

App.java
package com.sample.app;

public class App {

    public static void main(String args[]) {
        for (int i = Character.MIN_CODE_POINT; i < Character.MAX_CODE_POINT; i++) {
            if (Character.isJavaIdentifierStart(i)) {
                System.out.print((char) +i + " ");
            }
        }
    }

}




You may like

1 comment: