Using identifiers

Identifiers are used for class names, method names, and variable names.

An identifier may be any sequence of uppercase and lowercase letters, numbers, or the underscore and dollar-sign characters.

Identifiers must not begin with a number.

Java Identifiers are case-sensitive.

The following code illustrates some examples of valid identifiers:


public class Main {
  public static void main(String[] argv) {
    int ATEST, count, i1, $Atest, this_is_a_test;
  }

}

The following code shows invalid variable names include:


public class Main {
  public static void main(String[] argv){
     int 2count, h-l, a/b, 

  }
}

If you try to compile this code, you will get the following error message:


Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
	Syntax error on token "2", delete this token
	Syntax error on token "h", = expected after this token
	Syntax error on token ",", . expected
	Syntax error on token ",", ; expected

	at Main.main(Main.java:3)
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.