Tuesday, January 12, 2021

Java Identifier

 Java Identifier 

These are the names the programmers choose. These names can be assigned to variables, methods, functions, classes, etc., to uniquely identify from a compiler. Java keywords can not be used as an identifier.

Rules for Java Identifier:

1. The first character of an identifier must be a letter, an underscore(_), or a dollar sign($).
2. The rest of the characters in the identifier can be a letter, underscore, dollar sign, or digit. Note that spaces are not allowed in identifiers.
3. Identifier cannot match any of Java's keywords.
4. Identifiers are case-sensitive. This means that age and Age are different identifiers.

Valid Identifiers:

int a;
int hi_java;
int value4;
int $height;

Invalid Identifiers:

int hi java;  // uses a space
int 4value;  //start with digit
int for;   // for is keyword
int #height;  //does not start with dollar sign

Program for identifiers.

public class Identifier{
public static void main(String args[]){
int a=10;
int hi_java=12;
int value4=15;
int $height=33;
System.out.println("result is="+a);
System.out.println("result is="+hi_java);
System.out.println("result is="+value4);
System.out.println("result is="+$height);
}
}


Let's discuss our program and find identifiers:-

Identifier // which is the class name 
main  // main is method name
int a=10;
int hi_java=12;
int value4=15;
int $height=33;
String // Predefined class name
args  // variable name



No comments:

Post a Comment

Data Types in Java

 Data Types in Java Data Type in Java is defined as that specifies the size of memory allocated for a specific variable and which type of va...