Java Identifiers and Reserved Words

Java Identifiers
An identifier is a programmer-defined name for a variable, constant, class, method, package, object, etc.. in a program.

A Java identifier is a sequence of:
Letters from A to Z uppercase and lowercase.
Digits 0 to 9
The underscore _ and the dollar sign $
Any Unicode character over 00C0

An identifier cannot begin with a digit, cannot contain any white space and cannot contain any of the following special characters:
+ - * / = % & # ! ? ^ " ' ~ \ | < > ( ) [ ] { } : ; . ,
Java is case-sensitive: name and Name are different identifiers.
Legal Java identifiers are:
Age
name
_Price
$amount
gön
numberOfElements


Ilegal
Java identifiers:
4num      //begins with a digit
z#          //contains a special character #
"Age"      // contains a special character "
My name  //contains a white space

Java Reserved Words
The reserved words are identifiers that cannot be used as programmer-defined names. They are also called Keywords and are defined in the syntax of the language
The reserved words in Java are:
abstract
continue
for     
new        
switch
assert
default
goto
package
synchronized
boolean
do
if
private
this
break    
double  
implements
protected
throw
byte     
else    
import     
public       
throws
case     
enum
instanceof 
return      
transient
catch    
extends 
int        
short        
try
char     
final   
interface  
static       
void
class    
finally 
long       
strictfp     
volatile
const    
float   
native     
super        
while

No comments :

Post a Comment