Identifiers in Java

Any name in Java program is called Identifier. It could be a class name, variable name or method name.

Question: Find out list of identifiers in below program-
public class App {
 public static void main(String[] args) {
  int a = 10;
 }
}

Answer: 
1. Test
2. main
3. args
4. a

Rule:

1. The only allowed characters in Java identifier are:
   









2. Identifiers can't start with digit.


3. Java identifiers are case sensitive. Below are 3 different variables-
int Number =10;
int NumbeR =10;
int NUBber =10;

4. There is not length limit for Java identifiers but it is not commanded to take more than 15 length.

5. Reserved words can't be used as identifier.

6. All predefined Java classes name and interface names can be used as identifier. It is legal but not recommended.
We have declared variable names as String and Runnable in below program. It is valid.
public class App {
 public static void main(String[] args) {
  int String = 10;
  int Runnable = 20;
 }
}




Comments

Popular posts from this blog

Data types and Literals in Java

equals() method of Object class in Java

Create your own LinkedList in Java